Pandas version checks

  • [x] I have checked that this issue has not already been reported.

  • [x] I have confirmed this bug exists on the latest version of pandas.

  • [x] 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 https://github.com/pandas-dev/pandas/blob/6bcd30397d67c3887288c7a82c2c235ce8bc3c7f/pandas/core/series.py#L1835-L1850). 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 : 0691c5cf90477d3503834d983f69350f250a6ff7 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

Comment From: rhshadrach

Thanks for the report. Currently this is an inconsistency, but we will eventually be changing this so that all inplace=True return the instance. In addition, the inplace argument will be removed from rename. So closing this issue.

Ref: https://github.com/pandas-dev/pandas/pull/51466

Comment From: loicdiridollou

Great thanks for the note @rhshadrach. Are you interested in me changing the docs to reflect the new behavior? Happy to make a PR! Will have the pandas-stubs adjusted accordingly when this comes out!

Comment From: rhshadrach

@loicdiridollou - an update to the docs would be welcome!