ENH: CategoricalDtype repr should show dtype of categories · Issue #52179 · pandas-dev/pandas (original) (raw)

Feature Type

Problem Description

Right now the repr only shows the categories and if they are ordered, but since we can back Categoricals with arrow or nullable dtypes or generally different NumPy dtypes (e.g. int32) we should also show the dtype of the categories:

ser1 = Series(pd.Categorical(Index([1, 2, 3], dtype="int32")))
ser2 = Series(pd.Categorical(Index([1, 2, 3], dtype="int64")))

tm.assert_series_equal(ser1, ser2)

This shows

Attribute "dtype" are different
[left]:  CategoricalDtype(categories=[1, 2, 3], ordered=False)
[right]: CategoricalDtype(categories=[1, 2, 3], ordered=False)

which is not very helpful.

Feature Description

Add something like category_dtype="int32" to the repr.

Alternative Solutions

Not sure what you could do apart from checking explicitly for the categories dtype yourself.

Additional Context

No response