Skip to content

DOC: fix SA01 for pandas.MultiIndex.get_level_values #59400

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 @@ -70,7 +70,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
--format=actions \
-i ES01 `# For now it is ok if docstrings are missing the extended summary` \
-i "pandas.Series.dt PR01" `# Accessors are implemented as classes, but we do not document the Parameters section` \
-i "pandas.MultiIndex.get_level_values SA01" \
-i "pandas.MultiIndex.get_loc_level PR07" \
-i "pandas.MultiIndex.names SA01" \
-i "pandas.MultiIndex.reorder_levels RT03,SA01" \
Expand Down
17 changes: 17 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,16 @@ def get_level_values(self, level) -> Index: # type: ignore[override]
Return vector of label values for requested level.

Length of returned vector is equal to the length of the index.
The `get_level_values` method is a crucial utility for extracting
specific level values from a `MultiIndex`. This function is particularly
useful when working with multi-level data, allowing you to isolate
and manipulate individual levels without having to deal with the
complexity of the entire `MultiIndex` structure. It seamlessly handles
both integer and string-based level access, providing flexibility in
how you can interact with the data. Additionally, this method ensures
that the returned `Index` maintains the integrity of the original data,
even when missing values are present, by appropriately casting the
result to a suitable data type.

Parameters
----------
Expand All @@ -1796,6 +1806,13 @@ def get_level_values(self, level) -> Index: # type: ignore[override]
Values is a level of this MultiIndex converted to
a single :class:`Index` (or subclass thereof).

See Also
--------
MultiIndex : A multi-level, or hierarchical, index object for pandas objects.
Index : Immutable sequence used for indexing and alignment.
MultiIndex.remove_unused_levels : Create new MultiIndex from current that
removes unused levels.

Notes
-----
If the level contains missing values, the result may be casted to
Expand Down
Loading