Skip to content

Commit 8330de2

Browse files
DOC: Enforce Numpy Docstring Validation for pandas.DataFrame.swaplevel (#58566)
* DOC: add SA01 for pandas.DataFrame.swaplevel * DOC: remove SA01 for pandas.DataFrame.swaplevel
1 parent d765547 commit 8330de2

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7575
-i "pandas.DataFrame.median RT03,SA01" \
7676
-i "pandas.DataFrame.min RT03" \
7777
-i "pandas.DataFrame.plot PR02,SA01" \
78-
-i "pandas.DataFrame.swaplevel SA01" \
7978
-i "pandas.Grouper PR02" \
8079
-i "pandas.Index PR07" \
8180
-i "pandas.Index.ravel PR01,RT03" \

pandas/core/frame.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7642,16 +7642,30 @@ def nsmallest(
76427642
"""
76437643
return selectn.SelectNFrame(self, n=n, keep=keep, columns=columns).nsmallest()
76447644

7645-
@doc(
7646-
Series.swaplevel,
7647-
klass=_shared_doc_kwargs["klass"],
7648-
extra_params=dedent(
7649-
"""axis : {0 or 'index', 1 or 'columns'}, default 0
7650-
The axis to swap levels on. 0 or 'index' for row-wise, 1 or
7651-
'columns' for column-wise."""
7652-
),
7653-
examples=dedent(
7654-
"""\
7645+
def swaplevel(self, i: Axis = -2, j: Axis = -1, axis: Axis = 0) -> DataFrame:
7646+
"""
7647+
Swap levels i and j in a :class:`MultiIndex`.
7648+
7649+
Default is to swap the two innermost levels of the index.
7650+
7651+
Parameters
7652+
----------
7653+
i, j : int or str
7654+
Levels of the indices to be swapped. Can pass level name as string.
7655+
axis : {0 or 'index', 1 or 'columns'}, default 0
7656+
The axis to swap levels on. 0 or 'index' for row-wise, 1 or
7657+
'columns' for column-wise.
7658+
7659+
Returns
7660+
-------
7661+
DataFrame
7662+
DataFrame with levels swapped in MultiIndex.
7663+
7664+
See Also
7665+
--------
7666+
DataFrame.reorder_levels: Reorder levels of MultiIndex.
7667+
DataFrame.sort_index: Sort MultiIndex.
7668+
76557669
Examples
76567670
--------
76577671
>>> df = pd.DataFrame(
@@ -7701,10 +7715,8 @@ def nsmallest(
77017715
History Final exam January A
77027716
Geography Final exam February B
77037717
History Coursework March A
7704-
Geography Coursework April C"""
7705-
),
7706-
)
7707-
def swaplevel(self, i: Axis = -2, j: Axis = -1, axis: Axis = 0) -> DataFrame:
7718+
Geography Coursework April C
7719+
"""
77087720
result = self.copy(deep=False)
77097721

77107722
axis = self._get_axis_number(axis)

0 commit comments

Comments
 (0)