Skip to content

DOC: Wrong Series.rename parameter documentation #46889

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 done
leonarduschen opened this issue Apr 28, 2022 · 3 comments · Fixed by #48036
Closed
1 task done

DOC: Wrong Series.rename parameter documentation #46889

leonarduschen opened this issue Apr 28, 2022 · 3 comments · Fixed by #48036
Labels
Docs Needs Tests Unit test(s) needed to prevent regressions

Comments

@leonarduschen
Copy link
Contributor

Pandas version checks

  • I have checked that the issue still exists on the latest versions of the docs on main here

Location of the documentation

https://pandas.pydata.org/docs/reference/api/pandas.Series.rename.html

Documentation problem

Documentation says only inplace keyword is used, but actually other keywords from DataFrame.rename are valid

  • copy
import pandas as pd

s = pd.Series(["foo", "bar"])
shallow = s.rename({1: 9}, copy=False)
s[0] = "foobar"

print(s)
# 0    foobar
# 1       bar
# dtype: object

print(shallow)
# 0    foobar
# 9       bar
# dtype: object
  • errors
import pandas as pd

s = pd.Series(["foo", "bar"])
s.rename({2: 9}, errors="raise")  # This raises
  • level
import pandas as pd

arrays = [
    ["bar", "bar", "baz", "baz"],
    ["one", "two", "baz", "baz"],
]
tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=["first", "second"])
s = pd.Series([0, 1, 2, 3], index=index)

print(s)
# first  second
# bar    one       0
#        two       1
# baz    baz       2
#        baz       3
# dtype: int64

print(s.rename({"baz": "buz"}, level=1))
# first  second
# bar    one       0
#        two       1
# baz    buz       2
#        buz       3
# dtype: int64

Suggested fix for documentation

Document the above args - or just mention Series.rename accepts all args of DataFrame.rename except labels and columns

@leonarduschen leonarduschen added Docs Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 28, 2022
@rhshadrach rhshadrach added Needs Tests Unit test(s) needed to prevent regressions and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 29, 2022
@rhshadrach rhshadrach added this to the Contributions Welcome milestone Apr 29, 2022
@rhshadrach
Copy link
Member

Thanks for the report! Agreed either of your suggested fixes would be good; but I'd lean toward having a full docstring where each argument is described rather than referencing DataFrame's version.

I suspect this isn't tested but haven't checked, would be good to have tests too.

@jackgoldsmith4
Copy link
Contributor

@leonarduschen are you still working on this?

@leonarduschen
Copy link
Contributor Author

Yep, thanks for checking in!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants