Skip to content

Commit

Permalink
TST: Test CategoricalIndex in test_is_categorical
Browse files Browse the repository at this point in the history
Follow-up to pandas-devgh-16237.
  • Loading branch information
gfyoung committed May 4, 2017
1 parent 1a0c878 commit c476d0e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
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

0 comments on commit c476d0e

Please sign in to comment.