Skip to content

BUG: fix casting to a GeoSeries in to_geodataframe under new xarray #112

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 4 commits into from
May 3, 2025

Conversation

ilan-gold
Copy link
Contributor

Fixes #111

See pydata/xarray#10278 for further discussion

@ilan-gold
Copy link
Contributor Author

@martinfleis I think the whole test suite would benefit from a pass through at some point. The geom_array fixture is used repeatedly as a numpy array and then cast to a GeometryArray, it seems, to make testing for equality easier when xarray didn't handle this extension array stuff natively. So perhaps once the minimum version is bumped to a version of xarray where this geometry array type is preserved on the roundtrip, you can make geom_array natively as a fixture an extension array.

@martinfleis
Copy link
Member

Thanks for the fix but it was only partial. This would result in columns in a GeoDataFrame being a Series with a geometry dtype, hence no geopandas methods would work on them. We always need to cast to a GeoSeries. What this uncovered is actually a geopandas bug that does not allow us to cast a Series with a geometry dtype to a GeoSeries as geopandas expects this to be a GeoSeries and have .crs attribute. Will report upstream.

I have pushed a version of the fix that goes around while keeping the GeoSeries casting for any geometry column.

@martinfleis martinfleis changed the title (fix): don't cast to geopandas series if not needed BUG: fix casting to a GeoSeries in to_geodataframe under new xarray May 3, 2025
@martinfleis
Copy link
Member

It was actually fixed on geopandas main the meantime.

@martinfleis martinfleis merged commit a537364 into xarray-contrib:main May 3, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

⚠️ Nightly upstream-dev CI failed ⚠️
2 participants