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 with dtype raise instead of casting to NA #40996

Open
jbrockmendel opened this issue Apr 17, 2021 · 1 comment
Open
Labels
API - Consistency Internal Consistency of API/Behavior Categorical Categorical Data Type Constructors Series/DataFrame/Index/pd.array Constructors Error Reporting Incorrect or improved errors from pandas

Comments

@jbrockmendel
Copy link
Member

dti = pd.date_range("2016-01-01", periods=3)
ci = pd.Categorical(dti._values)

>>> pd.Categorical(["foo"], dtype=ci.dtype)
[NaT]
Categories (3, datetime64[ns]): [2016-01-01, 2016-01-02, 2016-01-03]

Casting "foo" to pd.NaT here makes very little sense to me, and does not match the behavior of any of our other constructors. I'm pretty sure this is why we have to do so much special-casing for Categorical in dtypes.cast and groupby ops.

Suggestion: we change/deprecate the behavior to raise instead of cast.

@jbrockmendel jbrockmendel added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 17, 2021
@jbrockmendel jbrockmendel added API - Consistency Internal Consistency of API/Behavior Categorical Categorical Data Type Constructors Series/DataFrame/Index/pd.array Constructors and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 6, 2021
@jbrockmendel
Copy link
Member Author

Discussed in April dev meeting, decided to try raising, see if that breaks the world, and if so deprecate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Categorical Categorical Data Type Constructors Series/DataFrame/Index/pd.array Constructors Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

No branches or pull requests

2 participants