Skip to content

Series.rename doesn't accept "axis" argument #18589

Closed
@toobaz

Description

@toobaz

Code Sample, a copy-pastable example if possible

In [2]: pd.Series(-1, index=range(3)).rename({}, axis=0)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-2588ce9f0737> in <module>()
----> 1 pd.Series(-1, index=range(3)).rename({}, axis=0)

/home/pietro/nobackup/repo/pandas/pandas/core/series.py in rename(self, index, **kwargs)
   2648         if non_mapping:
   2649             return self._set_name(index, inplace=kwargs.get('inplace'))
-> 2650         return super(Series, self).rename(index=index, **kwargs)
   2651 
   2652     @Appender(generic._shared_docs['reindex'] % _shared_doc_kwargs)

/home/pietro/nobackup/repo/pandas/pandas/core/generic.py in rename(self, *args, **kwargs)
    850         if kwargs:
    851             raise TypeError('rename() got an unexpected keyword '
--> 852                             'argument "{0}"'.format(list(kwargs.keys())[0]))
    853 
    854         if com._count_not_none(*axes.values()) == 0:

TypeError: rename() got an unexpected keyword argument "axis"

Problem description

Sure, it is redundant, but for compatibility it would be good to support it.

In particular, I have an old method which calls obj.rename_index(axis=n) with obj sometimes being a DataFrame and sometimes a Series, and now I get a warning asking me to use rename... but if I do, I get the above error.

Expected Output

The same as without axis=0.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: 2a0e54b
python: 3.5.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.0-4-amd64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8

pandas: 0.22.0.dev0+251.g2a0e54bc8
pytest: 3.0.6
pip: 9.0.1
setuptools: 33.1.1
Cython: 0.25.2
numpy: 1.12.1
scipy: 0.18.1
pyarrow: None
xarray: None
IPython: 5.2.2
sphinx: None
patsy: 0.4.1+dev
dateutil: 2.6.0
pytz: 2016.10
blosc: None
bottleneck: 1.2.0
tables: 3.3.0
numexpr: 2.6.1
feather: 0.3.1
matplotlib: 2.0.0
openpyxl: 2.3.0
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: None
lxml: 3.7.1
bs4: 4.5.3
html5lib: 0.999999999
sqlalchemy: 1.0.15
pymysql: None
psycopg2: None
jinja2: 2.8
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functionsEnhancementReshapingConcat, Merge/Join, Stack/Unstack, Explodegood first issue

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions