geopandas: BUG: explode() raises ValueError
Hi,
as reported here https://github.com/martinfleis/momepy/issues/123, at certain situation gdf.explode()
raises ValueError: Shape of passed values is (132850, 183), indices imply (132842, 183)
. Using data retrieved from OSM using OSMnx. (Warning - Vancouver gdf is large)
import geopandas as gpd
import osmnx as ox
gdf = ox.footprints.footprints_from_place(place='Vancouver, Canada')
gdf_projected = ox.project_gdf(gdf)
exploded = gdf_projected.explode()
I tried to save a small set to geojson, but after loading back to geopandas it does not cause the error 🤔
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 17 (9 by maintainers)
@seizethedata This bug is super strange with your data. I wasn’t able to figure out what happens there nor find a workaround with current version of geopandas. But I was able to patch explode to work with your data - #1319.
@seizethedata Try
reset_index()
before exploding.Hmm, that seems a bug. Can you report that to pandas?
Smaller reproducer:
Most of the entries don’t get exploded, only a few are actual MultiPolygons with multiple parts. Taking the first + one that gets exploded (found from
gdf.geometry.explode()
, on the GeoSeries it works), still gives the error:Further taking some columns as well:
Now, what I noticed when debugging this, is that it is the 2D object block that doesn’t get reshaped correctly:
And the original dataframe is also all object dtype (the geometry column as well, but that’s just because I am debugging on geopandas 0.5 where I had osmnx installed):
So let’s see if changing some to non-object dtype solves something, however, that doesn’t fix it:
Another specific thing about this dataset is that it has high integer indices (not default 0,1,2, n):
That seems to fix it! And it also does fix it on the original data:
So at least, that gives the original reporter a workaround. And hopefully those pointers can also help us find the cause 😉