Skip to content

BUG: .loc against CategoricalIndex may result in normal Index #11586

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

Closed
sinhrks opened this issue Nov 13, 2015 · 1 comment · Fixed by #11607
Closed

BUG: .loc against CategoricalIndex may result in normal Index #11586

sinhrks opened this issue Nov 13, 2015 · 1 comment · Fixed by #11607
Labels
Bug Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented Nov 13, 2015

.loc against CategoricalIndex with values included in its categories but not appears as codes results in normal Index

import numpy as np
import pandas as pd

index = pd.CategoricalIndex(list('aabbca'), categories=list('cabe'))
df = pd.DataFrame({'A' : np.arange(6,dtype='int64')}, index=index)

# OK
df.loc[['a', 'b']].index
# CategoricalIndex([u'a', u'a', u'a', u'b', u'b'], categories=[u'c', u'a', u'b', u'e'], ordered=False, dtype='category')

# NG, must be CategoricalIndex
df.loc[['a', 'b', 'e']].index
# Index([u'a', u'a', u'a', u'b', u'b', u'e'], dtype='object')

Even though this is tested here, it doesn't check dtype.

@sinhrks sinhrks added Bug Indexing Related to indexing on series/frames, not to indexes themselves Categorical Categorical Data Type labels Nov 13, 2015
@sinhrks sinhrks added this to the 0.17.1 milestone Nov 13, 2015
@jreback
Copy link
Contributor

jreback commented Nov 13, 2015

yeh that last does seem buggy.

@jreback jreback modified the milestones: Next Major Release, 0.17.1 Nov 13, 2015
@jreback jreback modified the milestones: 0.18.0, Next Major Release Nov 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants