-
-
Notifications
You must be signed in to change notification settings - Fork 956
BUG: explode() raises ValueError #1223
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
Comments
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
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. |
It is related to quite weird behaviour of
But if the order of index values is the opposite, it raises ValueError:
For some reason, index has to be sorted (that is why it works if you do reset_index). Using subset from above:
Explode works as intended. I will fix that by storing order and sorting it in the end. |
Hmm, that seems a bug. Can you report that to pandas? |
Will be fixed in pandas-dev/pandas#31113, closing here. Workaround for now is to |
@martinfleis unfortunately, |
@seizethedata Try |
@martinfleis I did that too. My code is:
|
You have to reset_index before exploding, not after. In case of reseting, you don't need to sort it. sp_blocks = blocks.reset_index(drop=True).explode() edit: you changed the code in the meantime. the one above should work, so it looks like a different issue. Can you make minimal reproducible example or share the data by any chance? |
Still the same, unfortunately. edit: Sorry, was inserting with code brackets wrong. |
@martinfleis I can share the data privately, if that's possible! |
Send them to [email protected]. |
I've sent the geojson to you |
@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. |
@martinfleis thanks! |
I appear to have the same bug after using # Mollweide projection epsg code
EPSG_CODE = 54009
# note: Mollweide defined by _esri_
# in epsg.io's database
CRS_PROJ = f"esri:{EPSG_CODE}"
CRS_WGS = "epsg:4326"
world = gp.read_file(
gp.datasets.get_path('naturalearth_lowres'),
crs=CRS_WGS)
world = world.to_crs(CRS_PROJ)
uk = world[world['name'] == "United Kingdom"]
fr = world[world['name'] == "France"]
# remove polygon from French Guiana
# and join back together as multipolygon
fr = fr.explode().iloc[1:].dissolve(by='name')
# the following works:
uk.explode()
# but not on France:
fr.explode()
# however, explode works with the workaround from martinfleis:
exploded_geom = fr.geometry.explode().reset_index(level=-1)
exploded_index = exploded_geom.columns[0]
fr_exploded = fr.drop(fr._geometry_column_name, axis=1).join(exploded_geom) |
Hi,
as reported here https://github.com/martinfleis/momepy/issues/123, at certain situation
gdf.explode()
raisesValueError: Shape of passed values is (132850, 183), indices imply (132842, 183)
. Using data retrieved from OSM using OSMnx. (Warning - Vancouver gdf is large)I tried to save a small set to geojson, but after loading back to geopandas it does not cause the error 🤔
The text was updated successfully, but these errors were encountered: