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

API: Categorical constructor shouldn't accept scalar for categories #16022

Closed
TomAugspurger opened this issue Apr 16, 2017 · 3 comments
Closed
Labels
API Design Categorical Categorical Data Type

Comments

@TomAugspurger
Copy link
Contributor

Code Sample, a copy-pastable example if possible

I was surprised to find that Categorical accepts scalars for categories.

In [1]: import pandas as pd
In [2]: pd.Categorical([1, 2], categories=2)
Out[2]:
[NaN, 2.0]
Categories (1, int64): [2]

AFAICT, this isn't documented, though we explicitly test it here. Am I missing a use-case where this is desirable, or should we just depreciate it and simplify the constructor?

Anyone want to guess what the categories are on pd.Categorical(['a', 'b'], categories='abcd') :)

cc @JanSchulz

@TomAugspurger TomAugspurger added API Design Categorical Categorical Data Type labels Apr 16, 2017
@TomAugspurger TomAugspurger added this to the Next Major Release milestone Apr 16, 2017
@jreback
Copy link
Contributor

jreback commented Apr 16, 2017

we generally do this, iow, accept scalars in list-like fields. So ok with this (also ok is to raise a ValueError). Maybe that would be better.

@jankatins
Copy link
Contributor

Not sure, I tried to find out if I wrote a message but it's all part of a squashed commit (0165d14), and none of the preserved comit messages show anything about it :-/ I think @jreback explaination is correct: it uses levels = _convert_to_list_like(levels), so it's the same logic as elsewhere...

@jorisvandenbossche
Copy link
Member

I would just raise an error on this, no reason to allow it IMO (and I would just regard it as a bug fix without deprecation, or would there be people doing this?)

TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue May 12, 2017
Categorical constructor no longer accepts scalars for categories.

Closes pandas-dev#16022
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue May 12, 2017
Categorical constructor no longer accepts scalars for categories.

Closes pandas-dev#16022
TomAugspurger added a commit to TomAugspurger/pandas that referenced this issue May 16, 2017
Categorical constructor no longer accepts scalars for categories.

Closes pandas-dev#16022
TomAugspurger added a commit that referenced this issue May 16, 2017
* BUG: Categorical constructor scalar categories

Categorical constructor no longer accepts scalars for categories.

Closes #16022
pcluo pushed a commit to pcluo/pandas that referenced this issue May 22, 2017
* BUG: Categorical constructor scalar categories

Categorical constructor no longer accepts scalars for categories.

Closes pandas-dev#16022
stangirala pushed a commit to stangirala/pandas that referenced this issue Jun 11, 2017
* BUG: Categorical constructor scalar categories

Categorical constructor no longer accepts scalars for categories.

Closes pandas-dev#16022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Categorical Categorical Data Type
Projects
None yet
Development

No branches or pull requests

4 participants