From 7cf00a23105a709b8184ba221076654a93def73f Mon Sep 17 00:00:00 2001 From: tp Date: Tue, 11 Jul 2017 22:13:21 +0100 Subject: [PATCH 1/4] Make _get_dtype accept pd.Categorical and pd.CategoricalIndex instances --- pandas/core/dtypes/common.py | 4 +++- pandas/tests/dtypes/test_common.py | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 2eebf3704253e..59846c9f164d9 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(' Date: Tue, 11 Jul 2017 22:47:11 +0100 Subject: [PATCH 2/4] small flake8 cleanup --- pandas/core/dtypes/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 59846c9f164d9..a386c04cc4fdd 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1714,7 +1714,7 @@ def _get_dtype(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 + return arr_or_dtype.dtype if hasattr(arr_or_dtype, 'dtype'): arr_or_dtype = arr_or_dtype.dtype From 3b4ef99a92b82a9054146f6e858944d121110ab7 Mon Sep 17 00:00:00 2001 From: tp Date: Wed, 12 Jul 2017 22:18:43 +0100 Subject: [PATCH 3/4] Added a note for change in dtypes.common._get_dtype in whatsnew --- doc/source/whatsnew/v0.21.0.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 015fdf1f45f47..4523569fb0f63 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -147,7 +147,8 @@ Bug Fixes Conversion ^^^^^^^^^^ - +- :func:`dtypes.common._get_dtype` now accepts ``Categorical``s and + ``CategoricalIndex`` (:issue:`16887`). Indexing ^^^^^^^^ From 54da1458f45161f3c6215dbe4e53711bf73dca88 Mon Sep 17 00:00:00 2001 From: topper-123 Date: Thu, 13 Jul 2017 21:32:51 +0100 Subject: [PATCH 4/4] Removed entry in whatsnew --- doc/source/whatsnew/v0.21.0.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 4523569fb0f63..40df813cf4b3b 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -147,8 +147,6 @@ Bug Fixes Conversion ^^^^^^^^^^ -- :func:`dtypes.common._get_dtype` now accepts ``Categorical``s and - ``CategoricalIndex`` (:issue:`16887`). Indexing ^^^^^^^^