Skip to content

API: make CategoricalDtype.__eq__ stricter #37929

Closed
@jbrockmendel

Description

@jbrockmendel

We allow for partially-initialized CategoricalDtypes to compare as equal to fully-initialized ones, leading to some surprising behaviors. The one that I stumbled over was this:

cat = pd.Categorical(["a", "b", "c"], ordered=True)
dtype = pd.CategoricalDtype()

>>> cat.dtype == dtype
True

cat2 = cat.astype(dtype)

>>> cat2.dtype == cat.dtype
False

We should stop special-casing categories=None for this purpose.

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