Skip to content

Commit d7fdeff

Browse files
jordan-d-murphypmhatre1
authored andcommitted
DOC: fix PR02 errors in docstring for pandas.Series.rename_axis (pandas-dev#57239)
* DOC: fix PR02 errors in docstring for pandas.Series.rename_axis * Refactor Series.rename_axis and NDFrame.rename_axis to have separate docstrings * removed unnecessary columns ref in docstring for Series * removed another unnecessary columns ref in docstring for Series
1 parent a1adb89 commit d7fdeff

File tree

3 files changed

+69
-25
lines changed

3 files changed

+69
-25
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
9191
pandas.TimedeltaIndex.floor\
9292
pandas.TimedeltaIndex.ceil\
9393
pandas.PeriodIndex.strftime\
94-
pandas.Series.rename_axis\
9594
pandas.Series.dt.to_period\
9695
pandas.Series.dt.tz_localize\
9796
pandas.Series.dt.tz_convert\

pandas/core/generic.py

+8-23
Original file line numberDiff line numberDiff line change
@@ -1158,18 +1158,18 @@ def rename_axis(
11581158
----------
11591159
mapper : scalar, list-like, optional
11601160
Value to set the axis name attribute.
1161-
index, columns : scalar, list-like, dict-like or function, optional
1162-
A scalar, list-like, dict-like or functions transformations to
1163-
apply to that axis' values.
1164-
Note that the ``columns`` parameter is not allowed if the
1165-
object is a Series. This parameter only apply for DataFrame
1166-
type objects.
11671161
11681162
Use either ``mapper`` and ``axis`` to
11691163
specify the axis to target with ``mapper``, or ``index``
11701164
and/or ``columns``.
1165+
index : scalar, list-like, dict-like or function, optional
1166+
A scalar, list-like, dict-like or functions transformations to
1167+
apply to that axis' values.
1168+
columns : scalar, list-like, dict-like or function, optional
1169+
A scalar, list-like, dict-like or functions transformations to
1170+
apply to that axis' values.
11711171
axis : {0 or 'index', 1 or 'columns'}, default 0
1172-
The axis to rename. For `Series` this parameter is unused and defaults to 0.
1172+
The axis to rename.
11731173
copy : bool, default None
11741174
Also copy underlying data.
11751175
@@ -1190,7 +1190,7 @@ def rename_axis(
11901190
11911191
Returns
11921192
-------
1193-
Series, DataFrame, or None
1193+
DataFrame, or None
11941194
The same type as the caller or None if ``inplace=True``.
11951195
11961196
See Also
@@ -1220,21 +1220,6 @@ def rename_axis(
12201220
12211221
Examples
12221222
--------
1223-
**Series**
1224-
1225-
>>> s = pd.Series(["dog", "cat", "monkey"])
1226-
>>> s
1227-
0 dog
1228-
1 cat
1229-
2 monkey
1230-
dtype: object
1231-
>>> s.rename_axis("animal")
1232-
animal
1233-
0 dog
1234-
1 cat
1235-
2 monkey
1236-
dtype: object
1237-
12381223
**DataFrame**
12391224
12401225
>>> df = pd.DataFrame({"num_legs": [4, 4, 2],

pandas/core/series.py

+61-1
Original file line numberDiff line numberDiff line change
@@ -5041,7 +5041,6 @@ def rename_axis(
50415041
) -> Self | None:
50425042
...
50435043

5044-
@doc(NDFrame.rename_axis)
50455044
def rename_axis(
50465045
self,
50475046
mapper: IndexLabel | lib.NoDefault = lib.no_default,
@@ -5051,6 +5050,67 @@ def rename_axis(
50515050
copy: bool = True,
50525051
inplace: bool = False,
50535052
) -> Self | None:
5053+
"""
5054+
Set the name of the axis for the index.
5055+
5056+
Parameters
5057+
----------
5058+
mapper : scalar, list-like, optional
5059+
Value to set the axis name attribute.
5060+
5061+
Use either ``mapper`` and ``axis`` to
5062+
specify the axis to target with ``mapper``, or ``index``.
5063+
5064+
index : scalar, list-like, dict-like or function, optional
5065+
A scalar, list-like, dict-like or functions transformations to
5066+
apply to that axis' values.
5067+
axis : {0 or 'index'}, default 0
5068+
The axis to rename. For `Series` this parameter is unused and defaults to 0.
5069+
copy : bool, default None
5070+
Also copy underlying data.
5071+
5072+
.. note::
5073+
The `copy` keyword will change behavior in pandas 3.0.
5074+
`Copy-on-Write
5075+
<https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__
5076+
will be enabled by default, which means that all methods with a
5077+
`copy` keyword will use a lazy copy mechanism to defer the copy and
5078+
ignore the `copy` keyword. The `copy` keyword will be removed in a
5079+
future version of pandas.
5080+
5081+
You can already get the future behavior and improvements through
5082+
enabling copy on write ``pd.options.mode.copy_on_write = True``
5083+
inplace : bool, default False
5084+
Modifies the object directly, instead of creating a new Series
5085+
or DataFrame.
5086+
5087+
Returns
5088+
-------
5089+
Series, or None
5090+
The same type as the caller or None if ``inplace=True``.
5091+
5092+
See Also
5093+
--------
5094+
Series.rename : Alter Series index labels or name.
5095+
DataFrame.rename : Alter DataFrame index labels or name.
5096+
Index.rename : Set new names on index.
5097+
5098+
Examples
5099+
--------
5100+
5101+
>>> s = pd.Series(["dog", "cat", "monkey"])
5102+
>>> s
5103+
0 dog
5104+
1 cat
5105+
2 monkey
5106+
dtype: object
5107+
>>> s.rename_axis("animal")
5108+
animal
5109+
0 dog
5110+
1 cat
5111+
2 monkey
5112+
dtype: object
5113+
"""
50545114
return super().rename_axis(
50555115
mapper=mapper,
50565116
index=index,

0 commit comments

Comments
 (0)