Skip to content

DOC: fix PR02 errors in docstring for pandas.Series.rename_axis #57239

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 5 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -93,7 +93,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\
Expand Down
54 changes: 32 additions & 22 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@
from pandas.core.indexers.objects import BaseIndexer
from pandas.core.resample import Resampler

import textwrap

# goal is to be able to define the docs close to function, while still being
# able to share
_shared_docs = {**_shared_docs}
Expand Down Expand Up @@ -1153,34 +1155,24 @@ def rename_axis(
) -> Self | None:
...

def rename_axis(
self,
mapper: IndexLabel | lib.NoDefault = lib.no_default,
*,
index=lib.no_default,
columns=lib.no_default,
axis: Axis = 0,
copy: bool_t | None = None,
inplace: bool_t = False,
) -> Self | None:
"""
Set the name of the axis for the index or columns.

Parameters
----------
@doc(
extra_parameters=textwrap.dedent(
"""\
mapper : scalar, list-like, optional
Value to set the axis name attribute.
index, columns : scalar, list-like, dict-like or function, optional
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.
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``.
axis : {0 or 'index', 1 or 'columns'}, default 0
axis : {{0 or 'index', 1 or 'columns'}}, default 0
The axis to rename. For `Series` this parameter is unused and defaults to 0.
copy : bool, default None
Also copy underlying data.
Expand All @@ -1199,7 +1191,25 @@ def rename_axis(
inplace : bool, default False
Modifies the object directly, instead of creating a new Series
or DataFrame.
"""
),
)
def rename_axis(
self,
mapper: IndexLabel | lib.NoDefault = lib.no_default,
*,
index=lib.no_default,
columns=lib.no_default,
axis: Axis = 0,
copy: bool_t | None = None,
inplace: bool_t = False,
) -> Self | None:
"""
Set the name of the axis for the index or columns.

Parameters
----------
{extra_parameters}
Returns
-------
Series, DataFrame, or None
Expand All @@ -1216,7 +1226,7 @@ def rename_axis(
``DataFrame.rename_axis`` supports two calling conventions

* ``(index=index_mapper, columns=columns_mapper, ...)``
* ``(mapper, axis={'index', 'columns'}, ...)``
* ``(mapper, axis={{'index', 'columns'}}, ...)``

The first calling convention will only modify the names of
the index and/or the names of the Index object that is the columns.
Expand Down Expand Up @@ -1249,8 +1259,8 @@ def rename_axis(

**DataFrame**

>>> df = pd.DataFrame({"num_legs": [4, 4, 2],
... "num_arms": [0, 0, 2]},
>>> df = pd.DataFrame({{"num_legs": [4, 4, 2],
... "num_arms": [0, 0, 2]}},
... ["dog", "cat", "monkey"])
>>> df
num_legs num_arms
Expand Down Expand Up @@ -1284,7 +1294,7 @@ def rename_axis(
cat 4 0
monkey 2 2

>>> df.rename_axis(index={'type': 'class'})
>>> df.rename_axis(index={{'type': 'class'}})
limbs num_legs num_arms
class name
mammal dog 4 0
Expand Down
34 changes: 33 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@
from pandas.core.frame import DataFrame
from pandas.core.groupby.generic import SeriesGroupBy

import textwrap

__all__ = ["Series"]

_shared_doc_kwargs = {
Expand Down Expand Up @@ -5173,7 +5175,37 @@ def rename_axis(
) -> Self | None:
...

@doc(NDFrame.rename_axis)
@doc(
NDFrame.rename_axis,
extra_parameters=textwrap.dedent(
"""\
mapper : scalar, list-like, optional
Value to set the axis name attribute.
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', 1 or 'columns'}}, 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
<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``
inplace : bool, default False
Modifies the object directly, instead of creating a new Series
or DataFrame.
"""
),
)
def rename_axis(
self,
mapper: IndexLabel | lib.NoDefault = lib.no_default,
Expand Down