Skip to content

fix to is_string #34294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down