Skip to content

Commit 662f97e

Browse files
authored
Bump minimum supported version to geopandas>=1.0 (#3908)
Bumps minimum supported GeoPandas version to 1.0 in the pyproject.toml and environment.yml files. Xref #3456 * Test geopandas=1.0 in ci_tests_legacy.yaml * Remove workaround for geopandas<1 in pygmt/helpers/tempfile.py Workaround added in #3247 for geopandas v0.x and v1.x compatibility. * Remove geopandas <1 and >=1 pin in ci_tests.yaml
1 parent ad43386 commit 662f97e

File tree

5 files changed

+15
-34
lines changed

5 files changed

+15
-34
lines changed

.github/workflows/ci_tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ jobs:
7575
numpy-version: '1.25'
7676
pandas-version: '=2.1'
7777
xarray-version: '=2023.04'
78-
optional-packages: ' contextily geopandas<1 ipython pyarrow-core rioxarray sphinx-gallery'
78+
optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray sphinx-gallery'
7979
# Python 3.13 + core packages (latest versions) + optional packages
8080
- python-version: '3.13'
8181
numpy-version: '2.2'
8282
pandas-version: ''
8383
xarray-version: ''
84-
optional-packages: ' contextily geopandas>=1.0 ipython pyarrow-core rioxarray sphinx-gallery'
84+
optional-packages: ' contextily geopandas ipython pyarrow-core rioxarray sphinx-gallery'
8585
# Python 3.12 + core packages (Linux only)
8686
- os: 'ubuntu-latest'
8787
python-version: '3.12'

.github/workflows/ci_tests_legacy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
netCDF4
6868
packaging
6969
contextily
70-
geopandas
70+
geopandas=1.0
7171
ipython
7272
pyarrow-core
7373
rioxarray

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies:
1414
- packaging
1515
# Optional dependencies
1616
- contextily
17-
- geopandas
17+
- geopandas>=1.0
1818
- ipython
1919
- pyarrow-core
2020
- rioxarray

pygmt/helpers/tempfile.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from tempfile import NamedTemporaryFile
1010

1111
import numpy as np
12-
from packaging.version import Version
1312

1413

1514
def unique_name() -> str:
@@ -144,34 +143,16 @@ def tempfile_from_geojson(geojson):
144143
# https://github.com/geopandas/geopandas/issues/967#issuecomment-842877704
145144
# https://github.com/GenericMappingTools/pygmt/issues/2497
146145
int32_info = np.iinfo(np.int32)
147-
# TODO(GeoPandas>=1.0): Remove the workaround for GeoPandas < 1.
148-
# The default engine is "fiona" in v0.x and "pyogrio" in v1.x.
149-
if Version(gpd.__version__).major < 1: # GeoPandas v0.x
150-
# The default engine 'fiona' supports the 'schema' parameter.
151-
if geojson.index.name is None:
152-
geojson.index.name = "index"
153-
geojson = geojson.reset_index(drop=False)
154-
schema = gpd.io.file.infer_schema(geojson)
155-
for col, dtype in schema["properties"].items():
156-
if dtype in {"int", "int64"}:
157-
overflow = (
158-
geojson[col].max() > int32_info.max
159-
or geojson[col].min() < int32_info.min
160-
)
161-
schema["properties"][col] = "float" if overflow else "int32"
162-
geojson[col] = geojson[col].astype(schema["properties"][col])
163-
ogrgmt_kwargs["schema"] = schema
164-
else: # GeoPandas v1.x.
165-
# The default engine "pyogrio" doesn't support the 'schema' parameter
166-
# but we can change the dtype directly.
167-
for col in geojson.columns:
168-
if geojson[col].dtype.name in {"int", "int64", "Int64"}:
169-
overflow = (
170-
geojson[col].max() > int32_info.max
171-
or geojson[col].min() < int32_info.min
172-
)
173-
dtype = "float" if overflow else "int32"
174-
geojson[col] = geojson[col].astype(dtype)
146+
# The default engine "pyogrio" doesn't support the 'schema' parameter
147+
# but we can change the dtype directly.
148+
for col in geojson.columns:
149+
if geojson[col].dtype.name in {"int", "int64", "Int64"}:
150+
overflow = (
151+
geojson[col].max() > int32_info.max
152+
or geojson[col].min() < int32_info.min
153+
)
154+
dtype = "float" if overflow else "int32"
155+
geojson[col] = geojson[col].astype(dtype)
175156
# Using geopandas.to_file to directly export to OGR_GMT format
176157
geojson.to_file(**ogrgmt_kwargs)
177158
except AttributeError:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dynamic = ["version"]
4646
[project.optional-dependencies]
4747
all = [
4848
"contextily",
49-
"geopandas",
49+
"geopandas>=1.0",
5050
"IPython", # 'ipython' is not the correct module name.
5151
"pyarrow",
5252
"rioxarray",

0 commit comments

Comments
 (0)