Skip to content

Commit 3124356

Browse files
committed
BUG: sort_index throws IndexError for some permutations (pandas-dev#26053)
- (lev - i) will be negative if 0th index is at the end of level list
1 parent e02ec8f commit 3124356

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pandas/core/indexes/multi.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -2085,8 +2085,11 @@ def sortlevel(self, level=0, ascending=True, sort_remaining=True):
20852085
shape = list(self.levshape)
20862086

20872087
# partition codes and shape
2088-
primary = tuple(codes.pop(lev - i) for i, lev in enumerate(level))
2089-
primshp = tuple(shape.pop(lev - i) for i, lev in enumerate(level))
2088+
primary = tuple(codes[lev] for lev in level)
2089+
primshp = tuple(shape[lev] for lev in level)
2090+
2091+
codes = []
2092+
shape = []
20902093

20912094
if sort_remaining:
20922095
primary += primary + tuple(codes)

0 commit comments

Comments
 (0)