On Series with CategoricalIndex, getitem not equal to .loc · Issue #15470 · pandas-dev/pandas (original) (raw)
Code Sample, a copy-pastable example if possible
s = pd.Series([2, 1, 0], index=pd.CategoricalIndex([2, 1, 0])) s.index CategoricalIndex([2, 1, 0], categories=[0, 1, 2], ordered=False, dtype='category') s[[0, 1, 2]].equals(s.loc[[0, 1, 2]]) # Should be True False s[[0, 1, 2]].equals(s.iloc[[0, 1, 2]]) # Should be False True
Problem description
For Series with CategoricalIndex, __getitem__
indexing behaves differently than .loc
. On other-indexed series, these accessors return the same result:
s = pd.Series([2, 1, 0], index=[2, 1, 0]) s[[0, 1, 2]].equals(s.loc[[0, 1, 2]]) # Should be True True s[[0, 1, 2]].equals(s.iloc[[0, 1, 2]]) # Should be True False
Expected Output
s = pd.Series([2, 1, 0], index=pd.CategoricalIndex([2, 1, 0])) s[[0, 1, 2]].equals(s.loc[[0, 1, 2]]) True
Output of pd.show_versions()
0.19.0+479.git