diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 015fdf1f45f47..40df813cf4b3b 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -148,7 +148,6 @@ Conversion ^^^^^^^^^^ - Indexing ^^^^^^^^ diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 2eebf3704253e..a386c04cc4fdd 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -11,7 +11,7 @@ ExtensionDtype) from .generic import (ABCCategorical, ABCPeriodIndex, ABCDatetimeIndex, ABCSeries, - ABCSparseArray, ABCSparseSeries) + ABCSparseArray, ABCSparseSeries, ABCCategoricalIndex) from .inference import is_string_like from .inference import * # noqa @@ -1713,6 +1713,8 @@ def _get_dtype(arr_or_dtype): return PeriodDtype.construct_from_string(arr_or_dtype) elif is_interval_dtype(arr_or_dtype): return IntervalDtype.construct_from_string(arr_or_dtype) + elif isinstance(arr_or_dtype, (ABCCategorical, ABCCategoricalIndex)): + return arr_or_dtype.dtype if hasattr(arr_or_dtype, 'dtype'): arr_or_dtype = arr_or_dtype.dtype diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index c32e8590c5675..7188e397c0617 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -532,16 +532,16 @@ def test_is_complex_dtype(): (float, np.dtype(float)), ('float64', np.dtype('float64')), (np.dtype('float64'), np.dtype('float64')), - pytest.mark.xfail((str, np.dtype('