Skip to content

Commit 1717a14

Browse files
committed
Minor change in how to determined if sorting is needed
1 parent c18d60d commit 1717a14

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

pandas/core/indexes/multi.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,19 +3103,20 @@ def _reorder_indexer(
31033103
-------
31043104
indexer : a sorted Int64Index indexer of self ordered as seq
31053105
"""
3106-
# Find out if the list_like label are sorted as the levels or not
3107-
need_sort = False
3108-
for i, k in enumerate(seq):
3109-
if is_list_like(k):
3110-
if not need_sort:
3111-
k_codes = self.levels[i].get_indexer(k)
3112-
k_codes = k_codes[k_codes >= 0] # Filter absent keys
3113-
# True if the given codes are not ordered
3114-
need_sort = (k_codes[:-1] > k_codes[1:]).any()
3115-
# Bail out if no need to sort
3116-
# This is only true for a lexsorted index
3117-
if not need_sort and self.is_lexsorted():
3118-
return indexer
3106+
# If the index is lexsorted and the list_like label in seq are sorted
3107+
# then we do not need to sort
3108+
if self.is_lexsorted():
3109+
need_sort = False
3110+
for i, k in enumerate(seq):
3111+
if is_list_like(k):
3112+
if not need_sort:
3113+
k_codes = self.levels[i].get_indexer(k)
3114+
k_codes = k_codes[k_codes >= 0] # Filter absent keys
3115+
# True if the given codes are not ordered
3116+
need_sort = (k_codes[:-1] > k_codes[1:]).any()
3117+
# Bail out if both index and seq are sorted
3118+
if not need_sort:
3119+
return indexer
31193120

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

0 commit comments

Comments
 (0)