Skip to content

Bump minimum supported version to geopandas>=1.0 #3908

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 7 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
4 changes: 2 additions & 2 deletions .github/workflows/ci_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ jobs:
numpy-version: '1.25'
pandas-version: '=2.1'
xarray-version: '=2023.04'
optional-packages: ' contextily geopandas<1 ipython pyarrow-core rioxarray sphinx-gallery'
optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray sphinx-gallery'
# Python 3.13 + core packages (latest versions) + optional packages
- python-version: '3.13'
numpy-version: '2.2'
pandas-version: ''
xarray-version: ''
optional-packages: ' contextily geopandas>=1.0 ipython pyarrow-core rioxarray sphinx-gallery'
optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray sphinx-gallery'
# Python 3.12 + core packages (Linux only)
- os: 'ubuntu-latest'
python-version: '3.12'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests_legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
netCDF4
packaging
contextily
geopandas
geopandas=1.0
ipython
pyarrow-core
rioxarray
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
- packaging
# Optional dependencies
- contextily
- geopandas
- geopandas>=1.0
- ipython
- pyarrow-core
- rioxarray
Expand Down
39 changes: 10 additions & 29 deletions pygmt/helpers/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from tempfile import NamedTemporaryFile

import numpy as np
from packaging.version import Version


def unique_name() -> str:
Expand Down Expand Up @@ -144,34 +143,16 @@ def tempfile_from_geojson(geojson):
# https://github.com/geopandas/geopandas/issues/967#issuecomment-842877704
# https://github.com/GenericMappingTools/pygmt/issues/2497
int32_info = np.iinfo(np.int32)
# TODO(GeoPandas>=1.0): Remove the workaround for GeoPandas < 1.
# The default engine is "fiona" in v0.x and "pyogrio" in v1.x.
if Version(gpd.__version__).major < 1: # GeoPandas v0.x
# The default engine 'fiona' supports the 'schema' parameter.
if geojson.index.name is None:
geojson.index.name = "index"
geojson = geojson.reset_index(drop=False)
schema = gpd.io.file.infer_schema(geojson)
for col, dtype in schema["properties"].items():
if dtype in {"int", "int64"}:
overflow = (
geojson[col].max() > int32_info.max
or geojson[col].min() < int32_info.min
)
schema["properties"][col] = "float" if overflow else "int32"
geojson[col] = geojson[col].astype(schema["properties"][col])
ogrgmt_kwargs["schema"] = schema
else: # GeoPandas v1.x.
# The default engine "pyogrio" doesn't support the 'schema' parameter
# but we can change the dtype directly.
for col in geojson.columns:
if geojson[col].dtype.name in {"int", "int64", "Int64"}:
overflow = (
geojson[col].max() > int32_info.max
or geojson[col].min() < int32_info.min
)
dtype = "float" if overflow else "int32"
geojson[col] = geojson[col].astype(dtype)
# The default engine "pyogrio" doesn't support the 'schema' parameter
# but we can change the dtype directly.
for col in geojson.columns:
if geojson[col].dtype.name in {"int", "int64", "Int64"}:
overflow = (
geojson[col].max() > int32_info.max
or geojson[col].min() < int32_info.min
)
dtype = "float" if overflow else "int32"
geojson[col] = geojson[col].astype(dtype)
# Using geopandas.to_file to directly export to OGR_GMT format
geojson.to_file(**ogrgmt_kwargs)
except AttributeError:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dynamic = ["version"]
[project.optional-dependencies]
all = [
"contextily",
"geopandas",
"geopandas>=1.0",
"IPython", # 'ipython' is not the correct module name.
"pyarrow",
"rioxarray",
Expand Down
Loading