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
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!