Skip to content

Commit a6a2f70

Browse files
committed
BUG: sort_index throws IndexError for some permutations (pandas-dev#26053)
1 parent e02ec8f commit a6a2f70

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pandas/core/indexes/multi.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -2085,8 +2085,17 @@ 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 = []
2089+
primshp = []
2090+
2091+
for lev in level:
2092+
primary.append(codes[lev])
2093+
primshp.append(shape[lev])
2094+
2095+
primary = tuple(primary)
2096+
primshp = tuple(primshp)
2097+
codes = []
2098+
shape = []
20902099

20912100
if sort_remaining:
20922101
primary += primary + tuple(codes)

0 commit comments

Comments
 (0)