-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
BUG: __getitem__ raise blank KeyError for IntervalIndex and missing keys #37873
Conversation
Tracking this down, it looks like the KeyError raised in Loc._validate_read_indexer has the well-written version of the message, and it looks like it is special-casing Categoricalndex for no apparent reason (CategoricalIndex and IntervalIndex being the only two Index subclasses that do the check this PR is looking at). Not yet totally sure, but it may be that we should always have this exception be raised in _validate_read_indexer |
@jbrockmendel I was thinking along the same line. One problem is, that we arrive in |
Can you track down when these comments got added? I think its likely that they are out of date. |
@phofl i came to the conclusion that the future-behavior you mentioned was supposed to have already been implemented, so those comments should be removed/updated. moreover, if we just remove IntervalIndex._convert_list_indexer altogether (and disable it from being called from CategoricalIndex._convert_list_indexer, we end up falling though to raise The remaining trouble is that the exception message isn't quite right for IntervalIndex bc it isnt a matter of the key not being present, but the key not being contained in any of the intervals. |
@jbrockmendel ok great. Will remove the code paths and update this pr with it. Should come to this tomorrow evening |
Removing
completly does not work out of the box.
where result has index Additionally, if disable calling it from
raises |
Thanks for giving it a try. I may have been overly optimistic about reducing code here. |
cc @jbrockmendel
This raises because
returns
I am not that familiar with interval support in this operation, but this seems at least odd. I would have expected one of the following:
Is my assumption correct? Then fixing this would bring us one step closer to removing this as you proposed |
This reverts commit 7127fb1
� Conflicts: � doc/source/whatsnew/v1.2.0.rst
This example doesn't raise for me on master. Do you mean in this branch?
indexing on a CategoricalIndex is difficult, and I think not entirely consistent (pretty sure there's an issue about this). IntervalIndex.get_loc/get_indexer behavior is pretty much unconnected to the |
Sorry, my question was rubbish without context. If we remove
from |
yah lets ignore this as orthogonal to this PR. can revisit later if we get ambitious about code simplification. |
this looks good, can you merge master @phofl if we want to open an issue about the actual error message ok by me. |
� Conflicts: � doc/source/whatsnew/v1.2.0.rst
thanks @phofl very nice, keep em coming (as you have been!) |
#25996 already exists for key error messages in general. |
Thanks very much, its fun working with you all |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Without
tolist
error would look likeKeyError: array([6])