Skip to content

Commit

Permalink
Add workaround for pandas 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Dec 12, 2024
1 parent 5867999 commit 56a266d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,12 @@ def _to_numpy(data: Any) -> np.ndarray:

# Deal with timezone-aware datetime dtypes.
if getattr(dtype, "tz", None): # pandas.DatetimeTZDtype
numpy_dtype = getattr(dtype, "base", None)
if Version(pd.__version__) < Version("2.1"):
# Workaround for bug https://github.com/pandas-dev/pandas/issues/52705.
# Solution from https://github.com/pandas-dev/pandas/pull/52706.
numpy_dtype = np.dtype(f"M8[{dtype.unit}]")
else:
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)
Expand Down

0 comments on commit 56a266d

Please sign in to comment.