Skip to content

SPEC 0: Bump minimum supported version to pandas>=2.1 #3895

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 4 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
# Python 3.11 + core packages (minimum supported versions) + optional packages (minimum supported versions if any)
- python-version: '3.11'
numpy-version: '1.25'
pandas-version: '=2.0'
pandas-version: '=2.1'
xarray-version: '=2023.04'
optional-packages: ' contextily geopandas<1 ipython pyarrow-core rioxarray sphinx-gallery'
# Python 3.13 + core packages (latest versions) + optional packages
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
- gmt=6.5.0
- ghostscript=10.04.0
- numpy>=1.25
- pandas>=2.0
- pandas>=2.1
- xarray>=2023.04
- netCDF4
- packaging
Expand Down
4 changes: 0 additions & 4 deletions pygmt/clib/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,6 @@ def _to_numpy(data: Any) -> np.ndarray:
elif isinstance(dtype, pd.ArrowDtype) and hasattr(dtype.pyarrow_dtype, "tz"):
# pd.ArrowDtype[pa.Timestamp]
numpy_dtype = getattr(dtype, "numpy_dtype", None)
# TODO(pandas>=2.1): Remove the workaround for pandas<2.1.
if Version(pd.__version__) < Version("2.1"):
# In pandas 2.0, dtype.numpy_type is dtype("O").
numpy_dtype = np.dtype(f"M8[{dtype.pyarrow_dtype.unit}]") # type: ignore[assignment, attr-defined]

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

Expand Down
19 changes: 2 additions & 17 deletions pygmt/tests/test_clib_to_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,7 @@ def test_to_numpy_pandas_numeric_with_na(dtype, expected_dtype):
"U10",
"string[python]",
pytest.param("string[pyarrow]", marks=skip_if_no(package="pyarrow")),
pytest.param(
"string[pyarrow_numpy]",
marks=[
skip_if_no(package="pyarrow"),
# TODO(pandas>=2.1): Remove the skipif marker for pandas<2.1.
pytest.mark.skipif(
Version(pd.__version__) < Version("2.1"),
reason="string[pyarrow_numpy] was added since pandas 2.1",
),
],
),
pytest.param("string[pyarrow_numpy]", marks=skip_if_no(package="pyarrow")),
],
)
def test_to_numpy_pandas_string(dtype):
Expand Down Expand Up @@ -536,12 +526,7 @@ def test_to_numpy_pandas_datetime(dtype, expected_dtype):

# Convert to UTC if the dtype is timezone-aware
if "," in str(dtype): # A hacky way to decide if the dtype is timezone-aware.
# TODO(pandas>=2.1): Simplify the if-else statement.
if Version(pd.__version__) < Version("2.1") and dtype.startswith("timestamp"):
# pandas 2.0 doesn't have the dt.tz_convert method for pyarrow.Timestamp.
series = pd.to_datetime(series, utc=True)
else:
series = series.dt.tz_convert("UTC")
series = series.dt.tz_convert("UTC")
# Remove time zone information and preserve local time.
expected_series = series.dt.tz_localize(tz=None)
npt.assert_array_equal(result, np.array(expected_series, dtype=expected_dtype))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ classifiers = [
]
dependencies = [
"numpy>=1.25",
"pandas>=2.0",
"pandas>=2.1",
"xarray>=2023.04",
"netCDF4",
"packaging",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Required packages
numpy>=1.25
pandas>=2.0
pandas>=2.1
xarray>=2023.04
netCDF4
packaging
Loading