momepy icon indicating copy to clipboard operation
momepy copied to clipboard

pandas 1.5.0 compatibility issues

Open martinfleis opened this issue 3 years ago • 15 comments

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

martinfleis avatar Sep 20 '22 15:09 martinfleis

Woah boy...

jGaboardi avatar Sep 20 '22 15:09 jGaboardi

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)`

jGaboardi avatar Sep 20 '22 19:09 jGaboardi

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

martinfleis avatar Sep 20 '22 22:09 martinfleis

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.

martinfleis avatar Sep 21 '22 19:09 martinfleis

~~Probably in numpy.nanpercentile, correct? Or is it specifically in pandas?~~

jGaboardi avatar Sep 21 '22 19:09 jGaboardi

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:

Screenshot 2022-09-21 at 21 56 24

So the issue seems to be within Tessellation. Digging deeper.

martinfleis avatar Sep 21 '22 19:09 martinfleis

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

martinfleis avatar Sep 21 '22 20:09 martinfleis

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.

martinfleis avatar Sep 21 '22 20:09 martinfleis

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.

martinfleis avatar Sep 21 '22 20:09 martinfleis

Excellent digging.

jGaboardi avatar Sep 21 '22 20:09 jGaboardi

See https://github.com/geopandas/geopandas/issues/2558 Got no clue what is happening.

martinfleis avatar Sep 21 '22 21:09 martinfleis

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()

jGaboardi avatar Sep 21 '22 21:09 jGaboardi

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.

martinfleis avatar Sep 21 '22 21:09 martinfleis

xref https://github.com/pandas-dev/pandas/pull/48711

jGaboardi avatar Sep 22 '22 13:09 jGaboardi

xref #437

jGaboardi avatar Oct 09 '22 14:10 jGaboardi

Fixed in pandas.

martinfleis avatar Jan 18 '23 14:01 martinfleis