Skip to content

Commit 6fdafda

Browse files
DOC: fix ES01,RT03,SA01 for pandas.MultiIndex.set_levels (#59367)
1 parent 7416a59 commit 6fdafda

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7575
-i "pandas.MultiIndex.names SA01" \
7676
-i "pandas.MultiIndex.remove_unused_levels RT03,SA01" \
7777
-i "pandas.MultiIndex.reorder_levels RT03,SA01" \
78-
-i "pandas.MultiIndex.set_levels RT03,SA01" \
7978
-i "pandas.MultiIndex.sortlevel PR07,SA01" \
8079
-i "pandas.MultiIndex.to_frame RT03" \
8180
-i "pandas.NA SA01" \

pandas/core/indexes/multi.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,19 @@ def set_levels(
933933
"""
934934
Set new levels on MultiIndex. Defaults to returning new index.
935935
936+
The `set_levels` method provides a flexible way to change the levels of a
937+
`MultiIndex`. This is particularly useful when you need to update the
938+
index structure of your DataFrame without altering the data. The method
939+
returns a new `MultiIndex` unless the operation is performed in-place,
940+
ensuring that the original index remains unchanged unless explicitly
941+
modified.
942+
943+
The method checks the integrity of the new levels against the existing
944+
codes by default, but this can be disabled if you are confident that
945+
your levels are consistent with the underlying data. This can be useful
946+
when you want to perform optimizations or make specific adjustments to
947+
the index levels that do not strictly adhere to the original structure.
948+
936949
Parameters
937950
----------
938951
levels : sequence or list of sequence
@@ -945,6 +958,14 @@ def set_levels(
945958
Returns
946959
-------
947960
MultiIndex
961+
A new `MultiIndex` with the updated levels.
962+
963+
See Also
964+
--------
965+
MultiIndex.set_codes : Set new codes on the existing `MultiIndex`.
966+
MultiIndex.remove_unused_levels : Create new MultiIndex from current that
967+
removes unused levels.
968+
Index.set_names : Set Index or MultiIndex name.
948969
949970
Examples
950971
--------

0 commit comments

Comments
 (0)