From 2aa6e7917000baffb6a14a89d9433bf8409edf5f Mon Sep 17 00:00:00 2001 From: gfyoung Date: Thu, 4 May 2017 19:31:48 -0400 Subject: [PATCH] TST: Test CategoricalIndex in test_is_categorical (#16243) Follow-up to gh-16237. --- pandas/core/dtypes/common.py | 4 +++- pandas/tests/dtypes/test_common.py | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 6c2bbe330eeee..bfec1ec3ebe8c 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -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) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 5b74397b1e770..4633dde5ed537 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -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])