Skip to content
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

DataFrame.rename only validates column arguments #29136

Closed
WillAyd opened this issue Oct 21, 2019 · 0 comments · Fixed by #29140
Closed

DataFrame.rename only validates column arguments #29136

WillAyd opened this issue Oct 21, 2019 · 0 comments · Fixed by #29140
Labels
Bug DataFrame DataFrame data structure
Milestone

Comments

@WillAyd
Copy link
Member

WillAyd commented Oct 21, 2019

Found this while trying to clean up axis handling in core.generic

This fails as you would hope

>>> df = pd.DataFrame([[1]])
>>> df.rename({0: 1}, columns={0: 2}, axis=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/williamayd/clones/pandas/pandas/util/_decorators.py", line 235, in wrapper
    return func(*args, **kwargs)
  File "/Users/williamayd/clones/pandas/pandas/core/frame.py", line 4143, in rename
    axes = validate_axis_style_args(self, args, kwargs, "mapper", "rename")
  File "/Users/williamayd/clones/pandas/pandas/util/_validators.py", line 287, in validate_axis_style_args
    raise TypeError(msg)
TypeError: Cannot specify both 'axis' and any of 'index' or 'columns'.

This doesn't

>>> df.rename({0: 1}, index={0: 2})
   0
1  1

And perhaps even more surprising is that you will get a different result depending on whether the first argument is passed by position or keyword

>>> df.rename(mapper={0: 1}, index={0: 2})
   0
2  1
@WillAyd WillAyd added the DataFrame DataFrame data structure label Oct 21, 2019
@jorisvandenbossche jorisvandenbossche added this to the Contributions Welcome milestone Oct 21, 2019
@jreback jreback modified the milestones: Contributions Welcome, 1.0 Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug DataFrame DataFrame data structure
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants