Skip to content

Commit 0309580

Browse files
committed
Remove workaround for geopandas<1 in pygmt/helpers/tempfile.py
Workaround added in #3247 for geopandas v0.x and v1.x compatibility.
1 parent 7294713 commit 0309580

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

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:

0 commit comments

Comments
 (0)