-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
COMPAT: catch InvalidIndexError in base Indexer getitem #27259
Conversation
@@ -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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ..
There was a problem hiding this comment.
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__
?
There was a problem hiding this comment.
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
@@ -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): |
There was a problem hiding this comment.
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__
?
thanks @jorisvandenbossche though would avoid using the internals in geopandas :-> |
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. |
@jbrockmendel yes, fully agree, was planning to do that so will do a follow up PR |
Closes #27258