Skip to content

DOC: fix ES01,RT03,SA01 for pandas.MultiIndex.set_levels #59367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.MultiIndex.names SA01" \
-i "pandas.MultiIndex.remove_unused_levels RT03,SA01" \
-i "pandas.MultiIndex.reorder_levels RT03,SA01" \
-i "pandas.MultiIndex.set_levels RT03,SA01" \
-i "pandas.MultiIndex.sortlevel PR07,SA01" \
-i "pandas.MultiIndex.to_frame RT03" \
-i "pandas.NA SA01" \
Expand Down
21 changes: 21 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,19 @@ def set_levels(
"""
Set new levels on MultiIndex. Defaults to returning new index.

The `set_levels` method provides a flexible way to change the levels of a
`MultiIndex`. This is particularly useful when you need to update the
index structure of your DataFrame without altering the data. The method
returns a new `MultiIndex` unless the operation is performed in-place,
ensuring that the original index remains unchanged unless explicitly
modified.

The method checks the integrity of the new levels against the existing
codes by default, but this can be disabled if you are confident that
your levels are consistent with the underlying data. This can be useful
when you want to perform optimizations or make specific adjustments to
the index levels that do not strictly adhere to the original structure.

Parameters
----------
levels : sequence or list of sequence
Expand All @@ -945,6 +958,14 @@ def set_levels(
Returns
-------
MultiIndex
A new `MultiIndex` with the updated levels.

See Also
--------
MultiIndex.set_codes : Set new codes on the existing `MultiIndex`.
MultiIndex.remove_unused_levels : Create new MultiIndex from current that
removes unused levels.
Index.set_names : Set Index or MultiIndex name.

Examples
--------
Expand Down
Loading