pysal / libpysal

Core components of Python Spatial Analysis Library
http://pysal.org/libpysal
Other
267 stars 78 forks source link

GeoDataFrame index ignored in `from_dataframe` class methods #473

Open TLouf opened 2 years ago

TLouf commented 2 years ago

As opposed to what's stated in the API docs, passing ids=None to a from_dataframe class method does not pass the df's index as ids.

Here's an MRE:

import libpysal
import geopandas as gpd
from shapely.geometry import box

gdf = gpd.GeoDataFrame(geometry=[box(1, 1, 2, 2), box(2, 1, 3, 2)], index=[1, 2])
w = libpysal.weights.Queen.from_dataframe(gdf)
print(w.id_order)

I don't know if it's the docstrings that haven't been updated after a change or if it's never been implemented, but either way I can open a PR to fix it if that's ok. Implementing it may break some user's code though, so I don't know if there should be some kind of deprecation period before making the change.

spolloni commented 2 years ago

I think this is related to https://github.com/pysal/libpysal/issues/474 in that here too the spatial weights class assumes the gdf index is always a default RangeIndex reflecting positional indices