Skip to content

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

Closed
@TomAugspurger

Description

@TomAugspurger

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions