Skip to content

DEPR: Make dtype="category" always imply ordered=False #61074

@mroeschke

Description

@mroeschke
Member

Currently one can specify dtype="category" to specify data as CategoricalDtype, and since it does not convey ordered information, we treat it as ordered=None internally in order to no-op data that is already categorical. Therefore internally, there are scenarios where we need to be mindful if we have ordered=None vs ordered=True/False

To simplify this gymnastics, it would be great if dtype="category" always meant CategoricalDtype(ordered=False). I think we would only need to issue a deprecation warning when specifying dtype="category" when the data is categorical and ordered=True

Activity

ZanirP

ZanirP commented on Mar 13, 2025

@ZanirP
Contributor

Hi! I would love to take this!

Just to clarify, the goal is to make dtype="category" always mean CategoricalDtype(ordered=False), with a deprecation warning when applied to CategoricalDtype(ordered=True).

So for example:

cat_ordered = pd.Categorical(["low", "medium", "high"], ordered=True)
categorical_data = cat_ordered.astype("category")

Current behavior is: CategoricalDtype(categories=['high', 'low', 'medium'], ordered=True, categories_dtype=object)
Expected behavior is: CategoricalDtype(categories=['high', 'low', 'medium'], ordered=False, categories_dtype=object) with a deprecation warning being raised (to inform users that ordering is being removed)?

Let me know if this sounds good!

ZanirP

ZanirP commented on Mar 13, 2025

@ZanirP
Contributor

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

CategoricalCategorical Data TypeDeprecateFunctionality to remove in pandas

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @mroeschke@ZanirP

    Issue actions

      DEPR: Make `dtype="category"` always imply ordered=False · Issue #61074 · pandas-dev/pandas