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

TomAugspurger opened this Issue Jan 22, 2018 · 3 comments


None yet
4 participants

TomAugspurger commented Jan 22, 2018

In [1]: import pandas as pd

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

In [3]: c
0    a
1    a
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.


This comment has been minimized.


cbertinato commented Feb 15, 2018

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.

@jreback jreback added this to the 0.23.0 milestone Feb 18, 2018


This comment has been minimized.


jschendel commented Mar 6, 2018

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


This comment has been minimized.


TomAugspurger commented Mar 6, 2018

Yep, thanks.

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