Skip to content
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

BUG/API: MultiIndex.get_level_values created from Categorical raises AttributeError #10460

Closed
sinhrks opened this issue Jun 28, 2015 · 1 comment
Labels
Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex
Milestone

Comments

@sinhrks
Copy link
Member

sinhrks commented Jun 28, 2015

import pandas as pd
import numpy as np
levels = ['foo', 'bar', 'baz', 'qux']
codes = np.random.randint(0, 4, size=100)

cats = pd.Categorical.from_codes(codes, levels, name='myfactor', ordered=True)

data = pd.DataFrame(np.random.randn(100, 4))
grouped = data.groupby(cats)
desc_result = grouped.describe()
desc_result.index.get_level_values(0)
# AttributeError: 'Categorical' object has no attribute 'flags'

Changing below line to use .get_values() looks fix the issue.

After the above change

desc_result.index.get_level_values(0)
CategoricalIndex([u'foo', u'foo', u'foo', u'foo', u'foo', u'foo', u'foo',
                  u'foo', u'bar', u'bar', u'bar', u'bar', u'bar', u'bar',
                  u'bar', u'bar', u'baz', u'baz', u'baz', u'baz', u'baz',
                  u'baz', u'baz', u'baz', u'qux', u'qux', u'qux', u'qux',
                  u'qux', u'qux', u'qux', u'qux'],
                 categories=[u'bar', u'baz', u'foo', u'qux'], ordered=False, name=u'myfactor', dtype='category')
@sinhrks sinhrks added Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex Categorical Categorical Data Type labels Jun 28, 2015
@sinhrks sinhrks added this to the 0.17.0 milestone Jun 28, 2015
@jreback
Copy link
Contributor

jreback commented Jun 28, 2015

might be same as #10324

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves MultiIndex
Projects
None yet
Development

No branches or pull requests

2 participants