Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
In [1]: import pandas as pd
In [2]: pd.Series([1, 2, 3])
Out[2]:
0 1
1 2
2 3
dtype: int64
In [3]: pd.Series([1, 2, 3]).rename('A')
Out[3]:
0 1
1 2
2 3
Name: A, dtype: int64
In [4]: pd.Series([1, 2, 3]).rename('A', inplace=True). # should return None
Out[4]:
0 1
1 2
2 3
Name: A, dtype: int64
Issue Description
According to the documation, inplace operations should return None and only modify the object in place without doing a deepcopy.
However when running the rename operation on pd.Series
with inplace=True
the type of the returns is pd.Series
and not None.
This seems to originate from quick look up in the _set_name
operations that return and object no matter the value of inplace
(cf
Lines 1835 to 1850 in 6bcd303
And then the
rename
operation only returns the result of _set_name
without distinguishing the inplace
value.
Expected Behavior
The docs suggest that the return of the rename(..., inplace=True)
should be None.
Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.13.1
python-bits : 64
OS : Darwin
OS-release : 24.3.0
Version : Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:06 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8103
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.2.3
numpy : 2.1.3
pytz : 2024.2
dateutil : 2.9.0.post0
pip : 24.3.1
Cython : None
sphinx : None
IPython : 8.29.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : 3.9.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : 8.3.3
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.2
qtpy : None
pyqt5 : None