From 25384ba459ba7de9fb9d36821f0a4ae239cc40b2 Mon Sep 17 00:00:00 2001 From: topper-123 Date: Thu, 13 Jul 2017 21:35:48 +0100 Subject: [PATCH] Let _get_dtype accept Categoricals and CategoricalIndex (#16887) --- doc/source/whatsnew/v0.21.0.txt | 1 - pandas/core/dtypes/common.py | 4 +++- pandas/tests/dtypes/test_common.py | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index a5ee0e0ce2653..8ba57c0fa50be 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -149,7 +149,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('