Skip to content

BUG: Change IntervalDtype.kind from None to "O" #30569

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 3 commits into from
Dec 31, 2019
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.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ Interval

- Bug in :meth:`IntervalIndex.get_indexer` where a :class:`Categorical` or :class:`CategoricalIndex` ``target`` would incorrectly raise a ``TypeError`` (:issue:`30063`)
- Bug in ``pandas.core.dtypes.cast.infer_dtype_from_scalar`` where passing ``pandas_dtype=True`` did not infer :class:`IntervalDtype` (:issue:`30337`)
- Bug in :class:`IntervalDtype` where the ``kind`` attribute was incorrectly set as ``None`` instead of ``"O"`` (:issue:`30568`)

Indexing
^^^^^^^^
Expand Down
9 changes: 8 additions & 1 deletion pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,14 @@ def is_string_dtype(arr_or_dtype) -> bool:

# TODO: gh-15585: consider making the checks stricter.
def condition(dtype) -> bool:
return dtype.kind in ("O", "S", "U") and not is_period_dtype(dtype)
return dtype.kind in ("O", "S", "U") and not is_excluded_dtype(dtype)

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)
return any(is_excluded(dtype) for is_excluded in is_excluded_checks)

return _is_dtype(arr_or_dtype, condition)

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ class IntervalDtype(PandasExtensionDtype):
"""

name = "interval"
kind: Optional[str_type] = None
kind: str_type = "O"
str = "|O08"
base = np.dtype("O")
num = 103
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 @@ -685,6 +685,10 @@ def test_caching(self):
tm.round_trip_pickle(dtype)
assert len(IntervalDtype._cache) == 0

def test_not_string(self):
# GH30568: though IntervalDtype has object kind, it cannot be string
assert not is_string_dtype(IntervalDtype())


class TestCategoricalDtypeParametrized:
@pytest.mark.parametrize(
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/extension/base/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def test_name(self, dtype):

def test_kind(self, dtype):
valid = set("biufcmMOSUV")
if dtype.kind is not None:
assert dtype.kind in valid
assert dtype.kind in valid

def test_construct_from_string_own_name(self, dtype):
result = dtype.construct_from_string(dtype.name)
Expand Down