DataFrame.rename only validates column arguments · Issue #29136 · pandas-dev/pandas (original) (raw)
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 "", line 1, in 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