Skip to content

Commit 3ca26ca

Browse files
committed
BUG/PERF: handle a slice correctly in get_level_indexer
1 parent c112252 commit 3ca26ca

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

pandas/indexes/multi.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -2069,20 +2069,14 @@ def convert_indexer(start, stop, step, indexer=indexer, labels=labels):
20692069
else:
20702070

20712071
loc = level_index.get_loc(key)
2072-
if level > 0 or self.lexsort_depth == 0:
2072+
if isinstance(loc, slice):
2073+
return loc
2074+
elif level > 0 or self.lexsort_depth == 0:
20732075
return np.array(labels == loc, dtype=bool)
2074-
else:
2075-
# sorted, so can return slice object -> view
2076-
try:
2077-
loc = labels.dtype.type(loc)
2078-
except TypeError:
2079-
# this occurs when loc is a slice (partial string indexing)
2080-
# but the TypeError raised by searchsorted in this case
2081-
# is catched in Index._has_valid_type()
2082-
pass
2083-
i = labels.searchsorted(loc, side='left')
2084-
j = labels.searchsorted(loc, side='right')
2085-
return slice(i, j)
2076+
2077+
i = labels.searchsorted(loc, side='left')
2078+
j = labels.searchsorted(loc, side='right')
2079+
return slice(i, j)
20862080

20872081
def get_locs(self, tup):
20882082
"""

0 commit comments

Comments
 (0)