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

Series constructor doesn't validate / reindex categorical #19342

Closed
TomAugspurger opened this issue Jan 22, 2018 · 3 comments
Closed

Series constructor doesn't validate / reindex categorical #19342

TomAugspurger opened this issue Jan 22, 2018 · 3 comments
Labels
Bug Categorical Categorical Data Type
Milestone

Comments

@TomAugspurger
Copy link
Contributor

In [1]: import pandas as pd

In [2]: c = pd.Series(pd.Categorical(['a', 'a']), index=[0, 1, 2])

In [3]: c
Out[3]:
0    a
1    a
2
dtype: category
Categories (1, object): [a]

In [4]: len(c)
Out[4]: 3

In [5]: len(c.values)
Out[5]: 2

This should probably raise.

@cbertinato
Copy link
Contributor

I'm going to make a pull request for this one, but just wanted to check on the strategy, in case I'm missing something else.

This appears to be an issue just for Categoricals in Series. Attempting to make a DataFrame of Categoricals with a mismatched index raises as expected. The issue is due to the fact that CategoricalBlock subclasses NonConsolidatableMixIn which sets _validate_ndim = False, so the check isn't done when constructing a Series with a Categorical. Setting that value to true elsewhere to fix this, say in CategoricalBlock, breaks functionality elsewhere. So it seems that a shallow fix in Series would be most appropriate.

@jschendel
Copy link
Member

I think this should be closed as the related PR has been merged?

@TomAugspurger
Copy link
Contributor Author

Yep, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type
Projects
None yet
Development

No branches or pull requests

4 participants