Skip to content

Commit

Permalink
Use data.dtype.numpy_dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Nov 5, 2024
1 parent c3471cb commit 176f511
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _to_numpy(data: Any) -> np.ndarray:
if hasattr(data, "isna") and data.isna().any():
# Integer dtypes with missing values are cast to NumPy float dtypes and NaN
# is used as missing value indicator.
dtype = np.float64 if data.dtype.kind in "iu" else data.dtype.type
dtype = np.float64 if data.dtype.kind in "iu" else data.dtype.numpy_dtype
data = data.to_numpy(dtype=dtype, na_value=np.nan)

vec_dtype = str(getattr(data, "dtype", ""))
Expand Down
4 changes: 3 additions & 1 deletion pygmt/tests/test_clib_to_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ def test_to_numpy_pandas_series_pandas_dtypes_numeric_with_na(dtype, supported):
# Integer dtypes with missing values are cast to NumPy float64 dtype, and Float
# dtypes with missing values are cast to NumPy float32/float64 dtype.
# np.NaN is used as missing value indicator.
expected_dtype = np.float64 if series.dtype.kind in "iu" else series.dtype.type
expected_dtype = (
np.float64 if series.dtype.kind in "iu" else series.dtype.numpy_dtype
)
npt.assert_array_equal(
result, np.array([1.0, np.nan, 3.0], dtype=expected_dtype), strict=True
)

0 comments on commit 176f511

Please sign in to comment.