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: allowing scalars in Categorical constructor #38433

Closed
jbrockmendel opened this issue Dec 12, 2020 · 2 comments · Fixed by #38472
Closed

BUG/API: allowing scalars in Categorical constructor #38433

jbrockmendel opened this issue Dec 12, 2020 · 2 comments · Fixed by #38472
Labels
Bug Categorical Categorical Data Type
Milestone

Comments

@jbrockmendel
Copy link
Member

I expected this to raise

>> pd.Categorical("A")
['A']
Categories (1, object): ['A']

This gets listified inside the call to maybe_infer_to_datetimelike in Categorical.__init__

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 12, 2020
@simonjayhawkins simonjayhawkins added Categorical Categorical Data Type and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 13, 2020
@simonjayhawkins
Copy link
Member

simonjayhawkins commented Dec 13, 2020

the docs for pd.Categorical do indeed suggest values should be list-like. and the string is NOT being interpreted as a list.

>>> pd.Categorical("ABC")
['ABC']
Categories (1, object): ['ABC']
>>>

this is a long standing behaviour, same result on 0.25.3

@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Dec 13, 2020
@jbrockmendel
Copy link
Member Author

Deep inside tests.arrays.categorical.test_constructors.TestCategoricalConstructors.test_constructor is

        # Scalars should be converted to lists
        cat = Categorical(1)
        assert len(cat.categories) == 1
        assert cat.categories[0] == 1
        assert len(cat.codes) == 1
        assert cat.codes[0] == 0

@jreback jreback modified the milestones: Contributions Welcome, 1.3 Dec 23, 2020
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

Successfully merging a pull request may close this issue.

3 participants