Skip to content

Broken usage of NDFrameIndexer in geopandas #27258

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DependenciesRequired and optional dependenciesIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions