-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
.loc should accept out-of-bounds indexers for slices #8740
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
Comments
that last is a big I think it doesn't make sense to accept out of bounds because by definition labels don't have bounds maybe show an example |
It seems to me by this argument I'm with @shoyer here, behaviour should be consistent with iloc. |
no the point is what is out of bounds I your example say I did but 20 is not in the index - what does that mean? and when would you then raise KeyError would be really odd |
that said if you have an example eould be best |
Sorry I wasn't clear, in the above I meant: doesn't your argument lead to disallowing s.loc[a:b] even with a and b are in the index. However, I don't see where the ambiguity is regardless of a and b being in the index, in python:
The problem arises if they are not orderable (i.e. but that's independent of whether they're in the index) ? |
I think this is a duplicate of #8613 I recently filed. But I am also in favor allowing out-of-bounds (not included labels) indexers in slices. There could only be some ambiguity with non-orderable values, but I think in most common cases this would be very useful. |
@jorisvandenbossche Oops, I think I even saw that issue a few weeks ago! Let's continue the discussion over there. I encountered this today as part of my recent indexing deep dive for intervals (#8707). |
pandas 0.14 changed
.iloc
to accept out-of-bounds indexers for slices. I think we should do the same for.loc
, for similar reasons of consistency and efficiency.Note that this is already currently inconsistent for int and float indexes (not entirely sure why):
The text was updated successfully, but these errors were encountered: