Skip to content

Commit c1c310d

Browse files
ieavesPuneethaPai
authored andcommitted
Fixes is_string_dtype (#34294)
1 parent cda6763 commit c1c310d

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

doc/source/whatsnew/v1.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ Backwards incompatible API changes
341341
will now result in a float column instead of an object dtyped column (:issue:`33607`)
342342
- :meth:`Series.to_timestamp` now raises a ``TypeError`` if the axis is not a :class:`PeriodIndex`. Previously an ``AttributeError`` was raised (:issue:`33327`)
343343
- :meth:`Series.to_period` now raises a ``TypeError`` if the axis is not a :class:`DatetimeIndex`. Previously an ``AttributeError`` was raised (:issue:`33327`)
344+
- :func: `pandas.api.dtypes.is_string_dtype` no longer incorrectly identifies categorical series as string.
344345

345346
``MultiIndex.get_indexer`` interprets `method` argument differently
346347
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

pandas/core/dtypes/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def is_excluded_dtype(dtype) -> bool:
599599
"""
600600
These have kind = "O" but aren't string dtypes so need to be explicitly excluded
601601
"""
602-
is_excluded_checks = (is_period_dtype, is_interval_dtype)
602+
is_excluded_checks = (is_period_dtype, is_interval_dtype, is_categorical_dtype)
603603
return any(is_excluded(dtype) for is_excluded in is_excluded_checks)
604604

605605
return _is_dtype(arr_or_dtype, condition)

pandas/tests/dtypes/test_dtypes.py

+4
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ def test_dtype_specific_categorical_dtype(self):
191191
result = str(Categorical(DatetimeIndex([])).categories.dtype)
192192
assert result == expected
193193

194+
def test_not_string(self):
195+
# though CategoricalDtype has object kind, it cannot be string
196+
assert not is_string_dtype(CategoricalDtype())
197+
194198

195199
class TestDatetimeTZDtype(Base):
196200
@pytest.fixture

0 commit comments

Comments
 (0)