Implement sort_remaining
for sort_index
#14033
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Previously, the
sort_remaining
argument tosort_index
was ignored. Passingsort_remaining=False
would raise aNotImplementedError
. Moreover, for a multiindex,sort_remaining=True
was not handled correctly: if not all levels were requested as sorted,sort_index
would behave as ifsort_remaining=False
had been passed.To fix this case, construct the sort order based on first the provided levels and, if
sort_remaining=True
, the left-over levels (in index order).To facilitate this, refactor the internal
_get_columns_by_label
function to always return aFrame
-like object (previously, if we had aFrame
we would get back aColumnAccessor
, and it was only forIndexedFrame
and above that we'd get something ofSelf
-like type back). This meant that calling_get_sorted_inds
withby != None
was not possible on anIndex
orMultiIndex
(the code assumed we'd get aFrame
back).Checklist