This is an automated email from the ASF dual-hosted git repository.
alenka pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new de9ff0d202 GH-48452: [Python] Add tests for Date32 and Date64 array
creation with masks (#48453)
de9ff0d202 is described below
commit de9ff0d202dde30dbe8322f6a992dd488b9ae134
Author: Hyukjin Kwon <[email protected]>
AuthorDate: Wed Jan 7 17:51:32 2026 +0900
GH-48452: [Python] Add tests for Date32 and Date64 array creation with
masks (#48453)
### Rationale for this change
The original ticket ARROW-4258 missed the followup task, see also
https://github.com/apache/arrow/pull/3395#issuecomment-454130648
Adding the test originally intended to test.
### What changes are included in this PR?
Added the tests dates with masks
### Are these changes tested?
Yes, manually tested as below:
```
python3 -m pytest
pyarrow/tests/test_pandas.py::test_create_date32_and_date64_arrays_with_mask
```
### Are there any user-facing changes?
No, test-only.
* GitHub Issue: #48452
Authored-by: Hyukjin Kwon <[email protected]>
Signed-off-by: AlenkaF <[email protected]>
---
python/pyarrow/tests/test_array.py | 52 +++++++++++++++++++++++++++++++++++++
python/pyarrow/tests/test_pandas.py | 2 --
2 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/python/pyarrow/tests/test_array.py
b/python/pyarrow/tests/test_array.py
index ec361159c5..cefa2de161 100644
--- a/python/pyarrow/tests/test_array.py
+++ b/python/pyarrow/tests/test_array.py
@@ -2216,6 +2216,58 @@ def test_date64_from_builtin_datetime():
assert as_i8[0].as_py() == as_i8[1].as_py()
+def test_create_date32_and_date64_arrays_with_mask():
+ # Test Date32 array creation from Python list with mask
+ arr_date32 = pa.array([0, 0, 1, 2],
+ mask=[False, False, True, False],
+ type=pa.date32())
+ expected_date32 = pa.array([
+ datetime.date(1970, 1, 1),
+ datetime.date(1970, 1, 1),
+ None,
+ datetime.date(1970, 1, 3),
+ ], type=pa.date32())
+ assert arr_date32.equals(expected_date32)
+
+ # Test Date32 array creation from Python dates
+ arr_date32_dates = pa.array([
+ datetime.date(2023, 1, 1),
+ datetime.date(2023, 1, 2),
+ None,
+ datetime.date(2023, 1, 4),
+ ], type=pa.date32())
+ assert arr_date32_dates.null_count == 1
+ assert arr_date32_dates[2].as_py() is None
+
+ # Test Date64 array creation from Python list with mask
+ arr_date64 = pa.array([0, 86400000, 172800000, 259200000],
+ mask=[False, False, True, False],
+ type=pa.date64())
+ expected_date64 = pa.array([
+ datetime.date(1970, 1, 1),
+ datetime.date(1970, 1, 2),
+ None,
+ datetime.date(1970, 1, 4),
+ ], type=pa.date64())
+ assert arr_date64.equals(expected_date64)
+
+ # Test Date64 array creation from Python dates
+ arr_date64_dates = pa.array([
+ datetime.date(2023, 1, 1),
+ datetime.date(2023, 1, 2),
+ None,
+ datetime.date(2023, 1, 4),
+ ], type=pa.date64())
+ assert arr_date64_dates.null_count == 1
+ assert arr_date64_dates[2].as_py() is None
+
+ # Test Date32 with all nulls mask
+ arr_all_null = pa.array([0, 1, 2, 3],
+ mask=[True, True, True, True],
+ type=pa.date32())
+ assert arr_all_null.null_count == 4
+
+
@pytest.mark.parametrize(('ty', 'values'), [
('bool', [True, False, True]),
('uint8', range(0, 255)),
diff --git a/python/pyarrow/tests/test_pandas.py
b/python/pyarrow/tests/test_pandas.py
index 4bcee62c37..daa9c8314a 100644
--- a/python/pyarrow/tests/test_pandas.py
+++ b/python/pyarrow/tests/test_pandas.py
@@ -3278,8 +3278,6 @@ class TestConvertMisc:
def test_safe_cast_from_float_with_nans_to_int():
- # TODO(kszucs): write tests for creating Date32 and Date64 arrays, see
- # ARROW-4258 and https://github.com/apache/arrow/pull/3395
values = pd.Series([1, 2, None, 4])
arr = pa.Array.from_pandas(values, type=pa.int32(), safe=True)
expected = pa.array([1, 2, None, 4], type=pa.int32())