Skip to content

Commit c068313

Browse files
jschendelTomAugspurger
authored andcommitted
BUG: Change IntervalDtype.kind from None to "O" (#30569)
* BUG: Change IntervalDtype.kind from None to "O"
1 parent 95be077 commit c068313

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ Interval
844844

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

848849
Indexing
849850
^^^^^^^^

pandas/core/dtypes/common.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,14 @@ def is_string_dtype(arr_or_dtype) -> bool:
633633

634634
# TODO: gh-15585: consider making the checks stricter.
635635
def condition(dtype) -> bool:
636-
return dtype.kind in ("O", "S", "U") and not is_period_dtype(dtype)
636+
return dtype.kind in ("O", "S", "U") and not is_excluded_dtype(dtype)
637+
638+
def is_excluded_dtype(dtype) -> bool:
639+
"""
640+
These have kind = "O" but aren't string dtypes so need to be explicitly excluded
641+
"""
642+
is_excluded_checks = (is_period_dtype, is_interval_dtype)
643+
return any(is_excluded(dtype) for is_excluded in is_excluded_checks)
637644

638645
return _is_dtype(arr_or_dtype, condition)
639646

pandas/core/dtypes/dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ class IntervalDtype(PandasExtensionDtype):
974974
"""
975975

976976
name = "interval"
977-
kind: Optional[str_type] = None
977+
kind: str_type = "O"
978978
str = "|O08"
979979
base = np.dtype("O")
980980
num = 103

pandas/tests/dtypes/test_dtypes.py

+4
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,10 @@ def test_caching(self):
685685
tm.round_trip_pickle(dtype)
686686
assert len(IntervalDtype._cache) == 0
687687

688+
def test_not_string(self):
689+
# GH30568: though IntervalDtype has object kind, it cannot be string
690+
assert not is_string_dtype(IntervalDtype())
691+
688692

689693
class TestCategoricalDtypeParametrized:
690694
@pytest.mark.parametrize(

pandas/tests/extension/base/dtype.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ def test_name(self, dtype):
1616

1717
def test_kind(self, dtype):
1818
valid = set("biufcmMOSUV")
19-
if dtype.kind is not None:
20-
assert dtype.kind in valid
19+
assert dtype.kind in valid
2120

2221
def test_construct_from_string_own_name(self, dtype):
2322
result = dtype.construct_from_string(dtype.name)

0 commit comments

Comments
 (0)