Skip to content

Commit bb77d11

Browse files
luke396pmhatre1
authored andcommitted
DOC: Add note and example for CategoricalDtype with different categories_dtype (pandas-dev#57273)
1 parent dcce45a commit bb77d11

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

doc/source/user_guide/categorical.rst

+12-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ Equality semantics
245245

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

250251
.. ipython:: python
251252
@@ -263,6 +264,16 @@ All instances of ``CategoricalDtype`` compare equal to the string ``'category'``
263264
264265
c1 == "category"
265266
267+
Notice that the ``categories_dtype`` should be considered, especially when comparing with
268+
two empty ``CategoricalDtype`` instances.
269+
270+
.. ipython:: python
271+
272+
c2 = pd.Categorical(np.array([], dtype=object))
273+
c3 = pd.Categorical(np.array([], dtype=float))
274+
275+
c2.dtype == c3.dtype
276+
266277
Description
267278
-----------
268279

0 commit comments

Comments
 (0)