Skip to content

Commit a537364

Browse files
BUG: fix casting to a GeoSeries in to_geodataframe under new xarray (#112)
* (fix): don't cast to geopandas series if not needed * (chore): lint * (fix): correct message * ensure we always get a GeoSeries --------- Co-authored-by: Martin Fleischmann <[email protected]>
1 parent 5d7c5d0 commit a537364

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

xvec/accessor.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -960,11 +960,16 @@ def to_geodataframe(
960960
if geometry is None:
961961
geometry = df.index.name
962962
df = df.reset_index()
963-
964963
# ensure CRS of all columns is preserved
965964
for c in df.columns:
966965
if c in self._geom_coords_all:
967-
df[c] = gpd.GeoSeries(df[c], crs=self._obj[c].attrs.get("crs", None))
966+
# there is a geopandas bug that does not allow upcasting a series
967+
# with a geometry dtype directly
968+
df[c] = gpd.GeoSeries(
969+
df[c].values,
970+
crs=self._obj[c].attrs.get("crs", None),
971+
index=df[c].index,
972+
)
968973

969974
if geometry is not None:
970975
if geometry not in self._geom_coords_all: # variable geometry

0 commit comments

Comments
 (0)