Skip to content

clib.conversion._to_numpy: Add tests for numpy array with np.datetime64 dtypes #3687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions pygmt/tests/test_clib_to_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,36 @@ def test_to_numpy_numpy_string(dtype):
npt.assert_array_equal(result, array)


@pytest.mark.parametrize(
"dtype",
[
np.datetime64, # The expected dtype is "datetime64[D]" for this test.
"datetime64[Y]",
"datetime64[M]",
"datetime64[W]",
"datetime64[D]",
"datetime64[h]",
"datetime64[m]",
"datetime64[s]",
"datetime64[ms]",
"datetime64[us]",
"datetime64[ns]",
],
)
def test_to_numpy_numpy_datetime(dtype):
"""
Test the _to_ndarray function with 1-D NumPy arrays of datetime.

Time units "fs", "as", "ps" are not tested here because they can only represent a
small range of times in 1969-1970.
"""
array = np.array(["2024-01-01", "2024-01-02", "2024-01-03"], dtype=dtype)
result = _to_numpy(array)
_check_result(result, np.datetime64)
assert result.dtype == (dtype if isinstance(dtype, str) else "datetime64[D]")
npt.assert_array_equal(result, array)


########################################################################################
# Test the _to_numpy function with pandas.Series.
#
Expand Down
Loading