Skip to content

Broken usage of NDFrameIndexer in geopandas #27258

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

Closed
jorisvandenbossche opened this issue Jul 6, 2019 · 3 comments · Fixed by #27259
Closed

Broken usage of NDFrameIndexer in geopandas #27258

jorisvandenbossche opened this issue Jul 6, 2019 · 3 comments · Fixed by #27259
Labels
Dependencies Required and optional dependencies Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@jorisvandenbossche
Copy link
Member

xref #27223 (comment)

The change in that PR broke a test in geopandas. We are using some indexing internals in geopandas that were relying on an InvalidIndexError being catched there (and the PR changed it to only TypeError and KeyError.

A small reproducible example without needing geopandas (but it is dummy code, not doing something useful):

from pandas.core.indexing import _NDFrameIndexer

class _CoordinateIndexer(_NDFrameIndexer):

    def _getitem_tuple(self, tup):
        obj = self.obj
        xs, ys = tup
        return obj[xs][ys]

pd.Series._create_indexer('cx', _CoordinateIndexer)

s = pd.Series(range(5))
s.cx[:, :]

The below passes on 0.24.2, but gives an error now on master.

The actual code in geopandas is:

https://github.com/geopandas/geopandas/blob/7c66c93f0f76de53615c02810e817ef57fb6a8de/geopandas/base.py#L734-L761

I know this is quite internal code of pandas that is being used here, so we should think about making this cleaner, but short term it would be nice to fix this.

@jbrockmendel
Copy link
Member

Could we come up with a just-pandas test case where we should catch InvalidIndexError there?

@jorisvandenbossche
Copy link
Member Author

With ix it seems possible. With the Series from above, s.ix[:, :] should give a "too many indexers" error (which it does not 0.24.2), but now gives InvalidIndexError. But yeah, since we are going to remove ix, that's also not a very good test :)

All the other indexers override this base __getitem__, so I don't there is anything else than ix in pandas that uses it.

@gfyoung gfyoung added Dependencies Required and optional dependencies Indexing Related to indexing on series/frames, not to indexes themselves labels Jul 6, 2019
@topper-123
Copy link
Contributor

@jorisvandenbossche Is there a status on this? I'm working on #30690, where ideally I'd like to remove the _create_index method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dependencies Required and optional dependencies Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants