Skip to content

Commit b376797

Browse files
DOC: fix PR07,SA01 for pandas.MultiIndex.sortlevel (#59521)
1 parent 0851ac3 commit b376797

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7272
-i "pandas.Series.dt PR01" `# Accessors are implemented as classes, but we do not document the Parameters section` \
7373
-i "pandas.MultiIndex.names SA01" \
7474
-i "pandas.MultiIndex.reorder_levels RT03,SA01" \
75-
-i "pandas.MultiIndex.sortlevel PR07,SA01" \
7675
-i "pandas.MultiIndex.to_frame RT03" \
7776
-i "pandas.NA SA01" \
7877
-i "pandas.NaT SA01" \

pandas/core/indexes/multi.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,8 +2681,15 @@ def sortlevel(
26812681
"""
26822682
Sort MultiIndex at the requested level.
26832683
2684-
The result will respect the original ordering of the associated
2685-
factor at that level.
2684+
This method is useful when dealing with MultiIndex objects, allowing for
2685+
sorting at a specific level of the index. The function preserves the
2686+
relative ordering of data within the same level while sorting
2687+
the overall MultiIndex. The method provides flexibility with the `ascending`
2688+
parameter to define the sort order and with the `sort_remaining` parameter to
2689+
control whether the remaining levels should also be sorted. Sorting a
2690+
MultiIndex can be crucial when performing operations that require ordered
2691+
indices, such as grouping or merging datasets. The `na_position` argument is
2692+
important in handling missing values consistently across different levels.
26862693
26872694
Parameters
26882695
----------
@@ -2692,7 +2699,9 @@ def sortlevel(
26922699
ascending : bool, default True
26932700
False to sort in descending order.
26942701
Can also be a list to specify a directed ordering.
2695-
sort_remaining : sort by the remaining levels after level
2702+
sort_remaining : bool, default True
2703+
If True, sorts by the remaining levels after sorting by the specified
2704+
`level`.
26962705
na_position : {'first' or 'last'}, default 'first'
26972706
Argument 'first' puts NaNs at the beginning, 'last' puts NaNs at
26982707
the end.
@@ -2706,6 +2715,13 @@ def sortlevel(
27062715
indexer : np.ndarray[np.intp]
27072716
Indices of output values in original index.
27082717
2718+
See Also
2719+
--------
2720+
MultiIndex : A multi-level, or hierarchical, index object for pandas objects.
2721+
Index.sort_values : Sort Index values.
2722+
DataFrame.sort_index : Sort DataFrame by the index.
2723+
Series.sort_index : Sort Series by the index.
2724+
27092725
Examples
27102726
--------
27112727
>>> mi = pd.MultiIndex.from_arrays([[0, 0], [2, 1]])

0 commit comments

Comments
 (0)