Skip to content

Commit 0e12376

Browse files
committed
Minor change in how to determined if sorting is needed
1 parent 3cdc493 commit 0e12376

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

pandas/core/indexes/multi.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -3071,19 +3071,20 @@ def _reorder_indexer(
30713071
-------
30723072
indexer : a sorted Int64Index indexer of self ordered as seq
30733073
"""
3074-
# Find out if the list_like label are sorted as the levels or not
3075-
need_sort = False
3076-
for i, k in enumerate(seq):
3077-
if is_list_like(k):
3078-
if not need_sort:
3079-
k_codes = self.levels[i].get_indexer(k)
3080-
k_codes = k_codes[k_codes >= 0] # Filter absent keys
3081-
# True if the given codes are not ordered
3082-
need_sort = (k_codes[:-1] > k_codes[1:]).any()
3083-
# Bail out if no need to sort
3084-
# This is only true for a lexsorted index
3085-
if not need_sort and self.is_lexsorted():
3086-
return indexer
3074+
# If the index is lexsorted and the list_like label in seq are sorted
3075+
# then we do not need to sort
3076+
if self.is_lexsorted():
3077+
need_sort = False
3078+
for i, k in enumerate(seq):
3079+
if is_list_like(k):
3080+
if not need_sort:
3081+
k_codes = self.levels[i].get_indexer(k)
3082+
k_codes = k_codes[k_codes >= 0] # Filter absent keys
3083+
# True if the given codes are not ordered
3084+
need_sort = (k_codes[:-1] > k_codes[1:]).any()
3085+
# Bail out if both index and seq are sorted
3086+
if not need_sort:
3087+
return indexer
30873088

30883089
n = len(self)
30893090
keys: Tuple[np.ndarray, ...] = tuple()

0 commit comments

Comments
 (0)