Skip to content

COMPAT: catch InvalidIndexError in base Indexer getitem #27259

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

Merged
merged 2 commits into from
Jul 8, 2019

Conversation

jorisvandenbossche
Copy link
Member

Closes #27258

@@ -118,7 +118,7 @@ def __getitem__(self, key):
key = tuple(com.apply_if_callable(x, self.obj) for x in key)
try:
values = self.obj._get_value(*key)
except (KeyError, TypeError):
except (KeyError, TypeError, InvalidIndexError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment about why this is caught here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to test this somehow as well?

Copy link
Member Author

@jorisvandenbossche jorisvandenbossche Jul 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #27258 for a discussion on that. I can add a test with the code snippet I show there, but is a rather dummy example ..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is fine, though why are you not using .loc and using __getitem__?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you not using .loc and using __getitem__?

This is from a custom Indexer attribute in geopandas, so it is on purpose not using .loc. Now, I don't say it is the best implementation by using such pandas internals, opened an issue about that in geopandas geopandas/geopandas#1042

@gfyoung gfyoung added Dependencies Required and optional dependencies Indexing Related to indexing on series/frames, not to indexes themselves labels Jul 6, 2019
@@ -118,7 +118,7 @@ def __getitem__(self, key):
key = tuple(com.apply_if_callable(x, self.obj) for x in key)
try:
values = self.obj._get_value(*key)
except (KeyError, TypeError):
except (KeyError, TypeError, InvalidIndexError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is fine, though why are you not using .loc and using __getitem__?

@jreback jreback added this to the 0.25.0 milestone Jul 8, 2019
@jreback jreback merged commit e607c34 into pandas-dev:master Jul 8, 2019
@jreback
Copy link
Contributor

jreback commented Jul 8, 2019

thanks @jorisvandenbossche though would avoid using the internals in geopandas :->

@jbrockmendel
Copy link
Member

I'd still like a comment here about why we are now catching InvalidIndexerError. Until recently this was catching Exception and I tracked down what actually gets raised, would prefer not to have to do that again in a few months.

@jorisvandenbossche jorisvandenbossche deleted the indexer-regression branch July 8, 2019 12:22
@jorisvandenbossche
Copy link
Member Author

@jbrockmendel yes, fully agree, was planning to do that so will do a follow up PR

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 this pull request may close these issues.

Broken usage of NDFrameIndexer in geopandas
4 participants