Skip to content

Commit e3dbdc5

Browse files
committed
Minor change in how to determined if sorting is needed
1 parent abbaf48 commit e3dbdc5

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
@@ -3074,19 +3074,20 @@ def _reorder_indexer(
30743074
-------
30753075
indexer : a sorted Int64Index indexer of self ordered as seq
30763076
"""
3077-
# Find out if the list_like label are sorted as the levels or not
3078-
need_sort = False
3079-
for i, k in enumerate(seq):
3080-
if is_list_like(k):
3081-
if not need_sort:
3082-
k_codes = self.levels[i].get_indexer(k)
3083-
k_codes = k_codes[k_codes >= 0] # Filter absent keys
3084-
# True if the given codes are not ordered
3085-
need_sort = (k_codes[:-1] > k_codes[1:]).any()
3086-
# Bail out if no need to sort
3087-
# This is only true for a lexsorted index
3088-
if not need_sort and self.is_lexsorted():
3089-
return indexer
3077+
# If the index is lexsorted and the list_like label in seq are sorted
3078+
# then we do not need to sort
3079+
if self.is_lexsorted():
3080+
need_sort = False
3081+
for i, k in enumerate(seq):
3082+
if is_list_like(k):
3083+
if not need_sort:
3084+
k_codes = self.levels[i].get_indexer(k)
3085+
k_codes = k_codes[k_codes >= 0] # Filter absent keys
3086+
# True if the given codes are not ordered
3087+
need_sort = (k_codes[:-1] > k_codes[1:]).any()
3088+
# Bail out if both index and seq are sorted
3089+
if not need_sort:
3090+
return indexer
30903091

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

0 commit comments

Comments
 (0)