diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index a3499f857d158..19db7dcb4b83e 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -341,6 +341,7 @@ Backwards incompatible API changes will now result in a float column instead of an object dtyped column (:issue:`33607`) - :meth:`Series.to_timestamp` now raises a ``TypeError`` if the axis is not a :class:`PeriodIndex`. Previously an ``AttributeError`` was raised (:issue:`33327`) - :meth:`Series.to_period` now raises a ``TypeError`` if the axis is not a :class:`DatetimeIndex`. Previously an ``AttributeError`` was raised (:issue:`33327`) +- :func: `pandas.api.dtypes.is_string_dtype` no longer incorrectly identifies categorical series as string. ``MultiIndex.get_indexer`` interprets `method` argument differently ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 5b20b8e1b3be5..a4a5ae1bfefff 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -599,7 +599,7 @@ def is_excluded_dtype(dtype) -> bool: """ These have kind = "O" but aren't string dtypes so need to be explicitly excluded """ - is_excluded_checks = (is_period_dtype, is_interval_dtype) + is_excluded_checks = (is_period_dtype, is_interval_dtype, is_categorical_dtype) return any(is_excluded(dtype) for is_excluded in is_excluded_checks) return _is_dtype(arr_or_dtype, condition) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index b55ff92e3f6a4..2684aa2c590d9 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -191,6 +191,10 @@ def test_dtype_specific_categorical_dtype(self): result = str(Categorical(DatetimeIndex([])).categories.dtype) assert result == expected + def test_not_string(self): + # though CategoricalDtype has object kind, it cannot be string + assert not is_string_dtype(CategoricalDtype()) + class TestDatetimeTZDtype(Base): @pytest.fixture