Skip to content

Commit

Permalink
Deal with timezone-aware datetime dtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Dec 12, 2024
1 parent 351247d commit 44f8106
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ def _to_numpy(data: Any) -> np.ndarray:
numpy_dtype = np.float64
data = data.to_numpy(na_value=np.nan)

# Deal with timezone-aware datetime dtypes.
if getattr(dtype, "tz", None): # pandas.DatetimeTZDtype
numpy_dtype = getattr(dtype, "base", None)
elif getattr(getattr(dtype, "pyarrow_dtype", None), "tz", None):
# pd.ArrayDtype[pa.Timestamp]
numpy_dtype = getattr(dtype, "numpy_dtype", None)

array = np.ascontiguousarray(data, dtype=numpy_dtype)

# Check if a np.object_ array can be converted to np.str_.
Expand Down

0 comments on commit 44f8106

Please sign in to comment.