-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
On Series with CategoricalIndex, __getitem__ not equal to .loc #15470
Comments
You have encountered a specific gotcha of getitem indexing. When you have a numerical index, it is label-based indexing (the second example you give). But for other types of indexes, it is positional indexing (eg try with strings). If we say it is not a numerical index (which I think we should do, as the way of indexing of a CategoricalIndex should IMO not depend on the type of the categories), the current behaviour is correct. But I admit this is rather confusing .. |
For some more discussion on getitem indexing, see #9595. The issue you raise here is yet another example of where the behaviour of getitem can be confusing/unpredictable due to the mixing of both label-based and positional indexing. |
It seems that this issue only occurs for list-like indexers, as a scalar label works correctly. With the example of above:
|
Code Sample, a copy-pastable example if possible
Problem description
For Series with CategoricalIndex,
__getitem__
indexing behaves differently than.loc
. On other-indexed series, these accessors return the same result:Expected Output
Output of
pd.show_versions()
0.19.0+479.git
The text was updated successfully, but these errors were encountered: