Skip to content

Commit

Permalink
DOC: fix SA01 error for pandas.Series.swaplevel (#58736)
Browse files Browse the repository at this point in the history
* DOC: add SA01 to pandas.Series.swaplevel

* DOC: remove SA01 to pandas.Series.swaplevel
  • Loading branch information
tuhinsharma121 committed May 16, 2024
1 parent 737c69c commit c121940
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 42 deletions.
1 change: 0 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Series.str.zfill RT03" \
-i "pandas.Series.struct.dtypes SA01" \
-i "pandas.Series.sum RT03" \
-i "pandas.Series.swaplevel SA01" \
-i "pandas.Series.to_dict SA01" \
-i "pandas.Series.to_frame SA01" \
-i "pandas.Series.to_markdown SA01" \
Expand Down
78 changes: 37 additions & 41 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3968,26 +3968,44 @@ def nsmallest(
"""
return selectn.SelectNSeries(self, n=n, keep=keep).nsmallest()

@doc(
klass=_shared_doc_kwargs["klass"],
extra_params=dedent(
"""copy : bool, default True
Whether to copy underlying data.
def swaplevel(
self, i: Level = -2, j: Level = -1, copy: bool | lib.NoDefault = lib.no_default
) -> Series:
"""
Swap levels i and j in a :class:`MultiIndex`.
.. note::
The `copy` keyword will change behavior in pandas 3.0.
`Copy-on-Write
<https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__
will be enabled by default, which means that all methods with a
`copy` keyword will use a lazy copy mechanism to defer the copy and
ignore the `copy` keyword. The `copy` keyword will be removed in a
future version of pandas.
Default is to swap the two innermost levels of the index.
Parameters
----------
i, j : int or str
Levels of the indices to be swapped. Can pass level name as string.
copy : bool, default True
Whether to copy underlying data.
.. note::
The `copy` keyword will change behavior in pandas 3.0.
`Copy-on-Write
<https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__
will be enabled by default, which means that all methods with a
`copy` keyword will use a lazy copy mechanism to defer the copy
and ignore the `copy` keyword. The `copy` keyword will be
removed in a future version of pandas.
You can already get the future behavior and improvements through
enabling copy on write ``pd.options.mode.copy_on_write = True``
Returns
-------
Series
Series with levels swapped in MultiIndex.
See Also
--------
DataFrame.swaplevel : Swap levels i and j in a :class:`DataFrame`.
Series.reorder_levels : Rearrange index levels using input order.
MultiIndex.swaplevel : Swap levels i and j in a :class:`MultiIndex`.
You can already get the future behavior and improvements through
enabling copy on write ``pd.options.mode.copy_on_write = True``"""
),
examples=dedent(
"""\
Examples
--------
>>> s = pd.Series(
Expand Down Expand Up @@ -4037,29 +4055,7 @@ def nsmallest(
Geography Final exam February B
History Coursework March A
Geography Coursework April C
dtype: object"""
),
)
def swaplevel(
self, i: Level = -2, j: Level = -1, copy: bool | lib.NoDefault = lib.no_default
) -> Series:
"""
Swap levels i and j in a :class:`MultiIndex`.
Default is to swap the two innermost levels of the index.
Parameters
----------
i, j : int or str
Levels of the indices to be swapped. Can pass level name as string.
{extra_params}
Returns
-------
{klass}
{klass} with levels swapped in MultiIndex.
{examples}
dtype: object
"""
self._check_copy_deprecation(copy)
assert isinstance(self.index, MultiIndex)
Expand Down

0 comments on commit c121940

Please sign in to comment.