Skip to content

Commit 97dbe2a

Browse files
committed
BUG: better exception on invalid slicing on CategoricalINdex
1 parent 5ef4159 commit 97dbe2a

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

pandas/core/indexes/category.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,6 @@ def _convert_list_indexer(self, keyarr):
535535

536536
return self.get_indexer_for(keyarr)
537537

538-
@doc(Index._maybe_cast_slice_bound)
539-
def _maybe_cast_slice_bound(self, label, side: str, kind):
540-
if kind == "loc":
541-
return label
542-
543-
return super()._maybe_cast_slice_bound(label, side, kind)
544-
545538
# --------------------------------------------------------------------
546539

547540
def _is_comparable_dtype(self, dtype):

pandas/tests/indexing/test_categorical.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,11 @@ def test_ix_categorical_index_non_unique(self):
469469

470470
def test_loc_slice(self):
471471
# GH9748
472-
with pytest.raises(KeyError, match="1"):
472+
msg = (
473+
"cannot do slice indexing on CategoricalIndex with these "
474+
r"indexers \[1\] of type int"
475+
)
476+
with pytest.raises(TypeError, match=msg):
473477
self.df.loc[1:5]
474478

475479
result = self.df.loc["b":"c"]

0 commit comments

Comments
 (0)