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

Comments

Projects
None yet
4 participants
@TomAugspurger
Contributor

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
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

This comment has been minimized.

Contributor

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

@jschendel

This comment has been minimized.

Member

jschendel commented Mar 6, 2018

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

@TomAugspurger

This comment has been minimized.

Contributor

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