Skip to content

Commit

Permalink
[Backport #14551] PERF: casting loc to labels dtype before searchsort…
Browse files Browse the repository at this point in the history
…ed (#14551)

(cherry picked from commit 1d95179)
  • Loading branch information
jorisvandenbossche committed Nov 3, 2016
1 parent 4c42422 commit a95ce63
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.19.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Performance Improvements
- Improved performance in ``.to_json()`` when ``lines=True`` (:issue:`14408`)
- Improved performance in ``Series.asof(where)`` when ``where`` is a scalar (:issue:`14461)
- Improved performance in ``DataFrame.asof(where)`` when ``where`` is a scalar (:issue:`14461)

- Improved performance in certain types of `loc` indexing with a MultiIndex (:issue:`14551`).



Expand Down
7 changes: 7 additions & 0 deletions pandas/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1907,6 +1907,13 @@ def convert_indexer(start, stop, step, indexer=indexer, labels=labels):
return np.array(labels == loc, dtype=bool)
else:
# sorted, so can return slice object -> view
try:
loc = labels.dtype.type(loc)
except TypeError:
# this occurs when loc is a slice (partial string indexing)
# but the TypeError raised by searchsorted in this case
# is catched in Index._has_valid_type()
pass
i = labels.searchsorted(loc, side='left')
j = labels.searchsorted(loc, side='right')
return slice(i, j)
Expand Down

0 comments on commit a95ce63

Please sign in to comment.