From 1048b13da68075494fddc3c317fcad88c9c7442c Mon Sep 17 00:00:00 2001 From: tuhinsharma121 Date: Thu, 16 May 2024 14:55:46 +0530 Subject: [PATCH 1/2] DOC: add SA01 to pandas.Series.swaplevel --- pandas/core/series.py | 78 ++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 97a53650ec5ff..302c1601b4566 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -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 - `__ - 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 + `__ + 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( @@ -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) From 49051c802c6f8edd2165750f70dff7dc0aa55740 Mon Sep 17 00:00:00 2001 From: tuhinsharma121 Date: Thu, 16 May 2024 14:56:01 +0530 Subject: [PATCH 2/2] DOC: remove SA01 to pandas.Series.swaplevel --- ci/code_checks.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index f93e87074d650..8548014abc099 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -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" \