Skip to content

DOC: Add notice and example for CategoricalDtype with different categories_dtype #57273

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

Merged
merged 8 commits into from
Feb 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion doc/source/user_guide/categorical.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ Equality semantics

Two instances of :class:`~pandas.api.types.CategoricalDtype` compare equal
whenever they have the same categories and order. When comparing two
unordered categoricals, the order of the ``categories`` is not considered.
unordered categoricals, the order of the ``categories`` is not considered. Note
that categories with different dtypes are not the same.

.. ipython:: python

Expand All @@ -263,6 +264,16 @@ All instances of ``CategoricalDtype`` compare equal to the string ``'category'``

c1 == "category"

Notice that the ``categories_dtype`` should be considered, especially when comparing with
two empty ``CategoricalDtype`` instances.

.. ipython:: python

c2 = pd.Categorical(np.array([], dtype=object))
c3 = pd.Categorical(np.array([], dtype=float))

c2.dtype == c3.dtype

Description
-----------

Expand Down