Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,15 @@ def is_categorical(arr):
>>> is_categorical([1, 2, 3])
False

Categoricals and Series Categoricals will return True.
Categoricals, Series Categoricals, and CategoricalIndex will return True.

>>> cat = pd.Categorical([1, 2, 3])
>>> is_categorical(cat)
True
>>> is_categorical(pd.Series(cat))
True
>>> is_categorical(pd.CategoricalIndex([1, 2, 3]))
True
"""

return isinstance(arr, ABCCategorical) or is_categorical_dtype(arr)
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def test_is_categorical():
cat = pd.Categorical([1, 2, 3])
assert com.is_categorical(cat)
assert com.is_categorical(pd.Series(cat))
assert com.is_categorical(pd.CategoricalIndex([1, 2, 3]))

assert not com.is_categorical([1, 2, 3])

Expand Down