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 068c5cb
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 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}]")

Check warning on line 201 in pygmt/clib/conversion.py

View check run for this annotation

Codecov / codecov/patch

pygmt/clib/conversion.py#L201

Added line #L201 was not covered by tests
else:
numpy_dtype = getattr(dtype, "base", None)

Check warning on line 203 in pygmt/clib/conversion.py

View check run for this annotation

Codecov / codecov/patch

pygmt/clib/conversion.py#L203

Added line #L203 was not covered by tests
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 068c5cb

Please sign in to comment.