@@ -143,6 +143,9 @@ def tempfile_from_geojson(geojson):
143
143
# 32-bit integer overflow issue. Related issues:
144
144
# https://github.com/geopandas/geopandas/issues/967#issuecomment-842877704
145
145
# https://github.com/GenericMappingTools/pygmt/issues/2497
146
+
147
+ int32_info = np .iinfo (np .int32 )
148
+
146
149
if Version (gpd .__version__ ).major < 1 : # GeoPandas v0.x
147
150
# The default engine 'fiona' supports the 'schema' parameter.
148
151
if geojson .index .name is None :
@@ -151,7 +154,10 @@ def tempfile_from_geojson(geojson):
151
154
schema = gpd .io .file .infer_schema (geojson )
152
155
for col , dtype in schema ["properties" ].items ():
153
156
if dtype in {"int" , "int64" }:
154
- overflow = geojson [col ].abs ().max () > 2 ** 31 - 1
157
+ overflow = (
158
+ geojson [col ].max () > int32_info .max
159
+ or geojson [col ].min () < int32_info .min
160
+ )
155
161
schema ["properties" ][col ] = "float" if overflow else "int32"
156
162
geojson [col ] = geojson [col ].astype (schema ["properties" ][col ])
157
163
ogrgmt_kwargs ["schema" ] = schema
@@ -160,7 +166,10 @@ def tempfile_from_geojson(geojson):
160
166
# but we can change the dtype directly.
161
167
for col in geojson .columns :
162
168
if geojson [col ].dtype .name in {"int" , "int64" , "Int64" }:
163
- overflow = geojson [col ].abs ().max () > 2 ** 31 - 1
169
+ overflow = (
170
+ geojson [col ].max () > int32_info .max
171
+ or geojson [col ].min () < int32_info .min
172
+ )
164
173
dtype = "float" if overflow else "int32"
165
174
geojson [col ] = geojson [col ].astype (dtype )
166
175
# Using geopandas.to_file to directly export to OGR_GMT format
0 commit comments