Skip to content

BUG: pd.Series.rename does not return None with inplace=True #42481

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

Closed
1 task
Omerdan03 opened this issue Jul 11, 2021 · 6 comments
Closed
1 task

BUG: pd.Series.rename does not return None with inplace=True #42481

Omerdan03 opened this issue Jul 11, 2021 · 6 comments
Labels
Bug inplace Relating to inplace parameter or equivalent Needs Discussion Requires discussion from core team before further action rename .rename, .rename_axis Series Series data structure

Comments

@Omerdan03
Copy link

Omerdan03 commented Jul 11, 2021

  • [ 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.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

ser = pd.Series([1,2,3], name='ser1')
f = ser.rename('ser2', inplace=True)

Problem description

f should be None like other inplace functionality.
instead f is Series object.

[this should explain why the current behaviour is a problem and why the expected output is a better solution]

Expected Output

Output of pd.show_versions()

INSTALLED VERSIONS

commit : b5958ee
python : 3.6.10.final.0
python-bits : 64
OS : Linux
OS-release : 5.8.0-59-generic
Version : #66~20.04.1-Ubuntu SMP Thu Jun 17 11:14:10 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.5
numpy : 1.19.5
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 52.0.0.post20210125
Cython : None
pytest : 6.2.3
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 1.3.9
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.16.1
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : 0.9.0
fastparquet : None
gcsfs : None
matplotlib : 3.3.4
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.4
sqlalchemy : None
tables : 3.6.1
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.53.1

@Omerdan03 Omerdan03 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 11, 2021
@Omerdan03
Copy link
Author

image

@mzeitlin11
Copy link
Member

Thanks for reporting this @Omerdan03! If you (or anyone else) is interested in contributing a fix, looks like the issue is here:

pandas/pandas/core/series.py

Lines 1750 to 1763 in 844b388

def _set_name(self, name, inplace=False) -> Series:
"""
Set the Series name.
Parameters
----------
name : str
inplace : bool
Whether to modify `self` directly or return a copy.
"""
inplace = validate_bool_kwarg(inplace, "inplace")
ser = self if inplace else self.copy()
ser.name = name
return ser

Hopefully just returning ser only if inplace=False would fix this and not break anything else

@mzeitlin11 mzeitlin11 added Series Series data structure and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 11, 2021
@mzeitlin11 mzeitlin11 added this to the Contributions Welcome milestone Jul 11, 2021
@Gdango
Copy link

Gdango commented Jul 12, 2021

Hello, I am new here. I would like to contribute to this issue.

@mzeitlin11
Copy link
Member

Hello, I am new here. I would like to contribute to this issue.

Looks like someone already put up a pr, please feel free to contribute to any other issues! (filtering by good first issue is also a good way to find good issues to start with)

@mroeschke mroeschke added the Needs Discussion Requires discussion from core team before further action label Aug 17, 2021
@jbrockmendel
Copy link
Member

Duplicate of #28920?

@jbrockmendel jbrockmendel added rename .rename, .rename_axis inplace Relating to inplace parameter or equivalent labels Oct 29, 2021
@jbrockmendel jbrockmendel changed the title BUG: pd.Series.rename BUG: pd.Series.rename does not return None with inplace=True Oct 29, 2021
@jbrockmendel
Copy link
Member

Closing as duplicate of #28920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug inplace Relating to inplace parameter or equivalent Needs Discussion Requires discussion from core team before further action rename .rename, .rename_axis Series Series data structure
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants