Skip to content

Commit 0bf733f

Browse files
authored
clib.conversion._to_numpy: Add tests for numpy array with np.datetime64 dtypes (#3687)
1 parent d33e5ac commit 0bf733f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pygmt/tests/test_clib_to_numpy.py

+30
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,36 @@ def test_to_numpy_numpy_string(dtype):
153153
npt.assert_array_equal(result, array)
154154

155155

156+
@pytest.mark.parametrize(
157+
"dtype",
158+
[
159+
np.datetime64, # The expected dtype is "datetime64[D]" for this test.
160+
"datetime64[Y]",
161+
"datetime64[M]",
162+
"datetime64[W]",
163+
"datetime64[D]",
164+
"datetime64[h]",
165+
"datetime64[m]",
166+
"datetime64[s]",
167+
"datetime64[ms]",
168+
"datetime64[us]",
169+
"datetime64[ns]",
170+
],
171+
)
172+
def test_to_numpy_numpy_datetime(dtype):
173+
"""
174+
Test the _to_ndarray function with 1-D NumPy arrays of datetime.
175+
176+
Time units "fs", "as", "ps" are not tested here because they can only represent a
177+
small range of times in 1969-1970.
178+
"""
179+
array = np.array(["2024-01-01", "2024-01-02", "2024-01-03"], dtype=dtype)
180+
result = _to_numpy(array)
181+
_check_result(result, np.datetime64)
182+
assert result.dtype == (dtype if isinstance(dtype, str) else "datetime64[D]")
183+
npt.assert_array_equal(result, array)
184+
185+
156186
########################################################################################
157187
# Test the _to_numpy function with pandas.Series.
158188
#

0 commit comments

Comments
 (0)