momepy
momepy copied to clipboard
pandas 1.5.0 compatibility issues
pandas 1.5 released yesterday broke our CI and is emitting a ton of new deprecation warnings.
https://github.com/pysal/momepy/actions/runs/3091088424/jobs/5000737392#step:6:187
Woah boy...
Not 100% sure why this is complaining so much. The message indicates the problem is with using .iloc, but we are using .loc there. I had thought using .loc was always safe for setting values in place?
elements.py:281: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the
values inplace instead of always setting a new array. To retain the old behavior, use either
`df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
The warning is a bit confusing but the change seem to apply to both loc and iloc - https://pandas.pydata.org/docs/whatsnew/v1.5.0.html#inplace-operation-when-setting-values-with-loc-and-iloc
The Percentiles broken in the SDSS 2022 tutorial are caused by pandas 1.5.0. With 1.4.4 as the only difference between the envs (numpy same in both), the issue is not present.
~~Probably in numpy.nanpercentile, correct? Or is it specifically in pandas?~~
Update - there is a mismatch in assigned unique_id in buildings and tessellation. The building and its tessellation cell should have the same id. They do not right after tessellation is created:

So the issue seems to be within Tessellation. Digging deeper.
One note aside - we have a bug in Percentiles as well. This should be the same as line 898 https://github.com/pysal/momepy/blob/c574bcfd8445dc8b5e54912cd8fe28ea10ff2cf5/momepy/diversity.py#L925
I've found where it gets messed up. https://github.com/pysal/momepy/blob/c574bcfd8445dc8b5e54912cd8fe28ea10ff2cf5/momepy/elements.py#L318-L320
clip seems to mess the order of geometries vs attributes. Still not sure where in clip that happens but it is a bug outside of momepy.
It happens here https://github.com/geopandas/geopandas/blob/af50debbbbeab62f3601518f814c9cb271b1859c/geopandas/tools/clip.py#L66-L68 There's absolutely no reason why this should happen. It must be a regression in pandas... This is a proper rabbit hole.
Excellent digging.
See https://github.com/geopandas/geopandas/issues/2558 Got no clue what is happening.
The TestElements.test_get_network_ratio failure appears to be also due to the geopandas.clip() problem.
Tessellation()->_enclosed_tessellation()->_tess()->_morphological_tessellation()->geopandas.clip()
The TestElements.test_get_network_ratio failure appears to be also due to the geopandas.clip() problem.
I am not fully sure about that, the mismatch between buildings and cells should not make a difference here. But could be.
xref https://github.com/pandas-dev/pandas/pull/48711
xref #437
Fixed in pandas.