Skip to content

Commit 1475837

Browse files
authored
clib.conversion._to_numpy: Add tests for pandas.Series with pyarrow date32/date64 types (#3610)
1 parent 851a203 commit 1475837

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pygmt/tests/test_clib_to_numpy.py

+22
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,28 @@ def test_to_numpy_pandas_series_numpy_dtypes_numeric(dtype, expected_dtype):
173173
npt.assert_array_equal(result, series)
174174

175175

176+
@pytest.mark.skipif(not _HAS_PYARROW, reason="pyarrow is not installed")
177+
@pytest.mark.parametrize(
178+
("dtype", "expected_dtype"),
179+
[
180+
pytest.param("date32[day][pyarrow]", "datetime64[D]", id="date32[day]"),
181+
pytest.param("date64[ms][pyarrow]", "datetime64[ms]", id="date64[ms]"),
182+
],
183+
)
184+
def test_to_numpy_pandas_series_pyarrow_dtypes_date(dtype, expected_dtype):
185+
"""
186+
Test the _to_numpy function with pandas.Series of PyArrow date32/date64 types.
187+
"""
188+
series = pd.Series(pd.date_range(start="2024-01-01", periods=3), dtype=dtype)
189+
result = _to_numpy(series)
190+
_check_result(result, np.datetime64)
191+
assert result.dtype == expected_dtype # Explicitly check the date unit.
192+
npt.assert_array_equal(
193+
result,
194+
np.array(["2024-01-01", "2024-01-02", "2024-01-03"], dtype=expected_dtype),
195+
)
196+
197+
176198
########################################################################################
177199
# Test the _to_numpy function with PyArrow arrays.
178200
#

0 commit comments

Comments
 (0)