Skip to content
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

DOC: fix ES01,RT03,SA01 for pandas.MultiIndex.remove_unused_levels #59366

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 @@ -76,7 +76,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.MultiIndex.get_loc_level PR07" \
-i "pandas.MultiIndex.levshape SA01" \
-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" \
Expand Down
13 changes: 13 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2041,9 +2041,22 @@ def remove_unused_levels(self) -> MultiIndex:
appearance, meaning the same .values and ordering. It will
also be .equals() to the original.

The `remove_unused_levels` method is useful in cases where you have a
MultiIndex with hierarchical levels, but some of these levels are no
longer needed due to filtering or subsetting operations. By removing
the unused levels, the resulting MultiIndex becomes more compact and
efficient, which can improve performance in subsequent operations.

Returns
-------
MultiIndex
A new MultiIndex with unused levels removed.

See Also
--------
MultiIndex.droplevel : Remove specified levels from a MultiIndex.
MultiIndex.reorder_levels : Rearrange levels of a MultiIndex.
MultiIndex.set_levels : Set new levels on a MultiIndex.

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