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

Closed
sinhrks opened this Issue Nov 13, 2015 · 1 comment

Comments

Projects
None yet
2 participants
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 added this to the 0.17.1 milestone Nov 13, 2015

Contributor

jreback commented Nov 13, 2015

yeh that last does seem buggy.

@jreback jreback modified the milestone: Next Major Release, 0.17.1 Nov 13, 2015

@jreback jreback modified the milestone: 0.18.0, Next Major Release Nov 20, 2015

jreback closed this in #11607 Nov 23, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment