@@ -1937,21 +1937,18 @@ def post_processor(vals: np.ndarray, inference: Optional[Type]) -> np.ndarray:
1937
1937
# >>> result.stack(0).loc[pd.IndexSlice[:, ..., q], :]
1938
1938
# but this hits https://github.com/pandas-dev/pandas/issues/10710
1939
1939
# which doesn't reorder the list-like `q` on the inner level.
1940
- order = np .roll (list (range (result .index .nlevels )), - 1 )
1940
+ order = np .append (np .arange (1 , result .index .nlevels ), 0 )
1941
+ # temporarily saves the index names
1942
+ index_names = np .array (result .index .names )
1943
+ # set index names to positions to avoid confusion
1944
+ result .index .names = np .arange (len (index_names ))
1945
+ # place quantiles on the inside
1941
1946
result = result .reorder_levels (order )
1942
- result = result .reindex (q , level = - 1 )
1947
+ # restore the index names in order
1948
+ result .index .names = index_names [order ]
1943
1949
1944
- # fix order.
1945
- hi = len (q ) * self .ngroups
1946
- arr = np .arange (0 , hi , self .ngroups )
1947
- arrays = []
1948
-
1949
- for i in range (self .ngroups ):
1950
- arr2 = arr + i
1951
- arrays .append (arr2 )
1952
-
1953
- indices = np .concatenate (arrays )
1954
- assert len (indices ) == len (result )
1950
+ # reorder rows to keep things sorted
1951
+ indices = np .arange (len (result )).reshape ([len (q ), self .ngroups ]).T .flatten ()
1955
1952
return result .take (indices )
1956
1953
1957
1954
@Substitution (name = "groupby" )
0 commit comments