diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 2eb5b73d68964..14ff227b805dd 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -92,7 +92,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.TimedeltaIndex.ceil\ pandas.PeriodIndex\ pandas.PeriodIndex.strftime\ - pandas.Series.rename_axis\ pandas.Series.dt.to_period\ pandas.Series.dt.tz_localize\ pandas.Series.dt.tz_convert\ diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 490a47d16871c..0ca46f9987859 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1170,18 +1170,18 @@ def rename_axis( ---------- mapper : scalar, list-like, optional Value to set the axis name attribute. - index, columns : scalar, list-like, dict-like or function, optional - A scalar, list-like, dict-like or functions transformations to - apply to that axis' values. - Note that the ``columns`` parameter is not allowed if the - object is a Series. This parameter only apply for DataFrame - type objects. Use either ``mapper`` and ``axis`` to specify the axis to target with ``mapper``, or ``index`` and/or ``columns``. + index : scalar, list-like, dict-like or function, optional + A scalar, list-like, dict-like or functions transformations to + apply to that axis' values. + columns : scalar, list-like, dict-like or function, optional + A scalar, list-like, dict-like or functions transformations to + apply to that axis' values. axis : {0 or 'index', 1 or 'columns'}, default 0 - The axis to rename. For `Series` this parameter is unused and defaults to 0. + The axis to rename. copy : bool, default None Also copy underlying data. @@ -1202,7 +1202,7 @@ def rename_axis( Returns ------- - Series, DataFrame, or None + DataFrame, or None The same type as the caller or None if ``inplace=True``. See Also @@ -1232,21 +1232,6 @@ def rename_axis( Examples -------- - **Series** - - >>> s = pd.Series(["dog", "cat", "monkey"]) - >>> s - 0 dog - 1 cat - 2 monkey - dtype: object - >>> s.rename_axis("animal") - animal - 0 dog - 1 cat - 2 monkey - dtype: object - **DataFrame** >>> df = pd.DataFrame({"num_legs": [4, 4, 2], diff --git a/pandas/core/series.py b/pandas/core/series.py index 94be7bdbaca16..d30efd0e27480 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -5133,7 +5133,6 @@ def rename_axis( ) -> Self | None: ... - @doc(NDFrame.rename_axis) def rename_axis( self, mapper: IndexLabel | lib.NoDefault = lib.no_default, @@ -5143,6 +5142,67 @@ def rename_axis( copy: bool = True, inplace: bool = False, ) -> Self | None: + """ + Set the name of the axis for the index. + + Parameters + ---------- + mapper : scalar, list-like, optional + Value to set the axis name attribute. + + Use either ``mapper`` and ``axis`` to + specify the axis to target with ``mapper``, or ``index``. + + index : scalar, list-like, dict-like or function, optional + A scalar, list-like, dict-like or functions transformations to + apply to that axis' values. + axis : {0 or 'index'}, default 0 + The axis to rename. For `Series` this parameter is unused and defaults to 0. + copy : bool, default None + Also 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`` + inplace : bool, default False + Modifies the object directly, instead of creating a new Series + or DataFrame. + + Returns + ------- + Series, or None + The same type as the caller or None if ``inplace=True``. + + See Also + -------- + Series.rename : Alter Series index labels or name. + DataFrame.rename : Alter DataFrame index labels or name. + Index.rename : Set new names on index. + + Examples + -------- + + >>> s = pd.Series(["dog", "cat", "monkey"]) + >>> s + 0 dog + 1 cat + 2 monkey + dtype: object + >>> s.rename_axis("animal") + animal + 0 dog + 1 cat + 2 monkey + dtype: object + """ return super().rename_axis( mapper=mapper, index=index,