Repository: pandas-dev/pandas

Issue:
Series.rename doesn't accept "axis" argument
#### Code Sample, a copy-pastable example if possible

```python
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()``

<details>

INSTALLED VERSIONS
------------------
commit: 2a0e54bc841f27164b116135ebda4b74bae2fc4a
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


</details>



Discussion:
sure for compat this would be ok

Resolving patch:
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -863,6 +863,9 @@ def rename(self, *args, **kwargs):
         copy = kwargs.pop('copy', True)
         inplace = kwargs.pop('inplace', False)
         level = kwargs.pop('level', None)
+        axis = kwargs.pop('axis', None)
+        if axis is not None:
+            axis = self._get_axis_number(axis)
 
         if kwargs:
             raise TypeError('rename() got an unexpected keyword '


Test patch:
diff --git a/pandas/tests/series/test_alter_axes.py b/pandas/tests/series/test_alter_axes.py
--- a/pandas/tests/series/test_alter_axes.py
+++ b/pandas/tests/series/test_alter_axes.py
@@ -81,6 +81,14 @@ def test_rename_set_name_inplace(self):
             exp = np.array(['a', 'b', 'c'], dtype=np.object_)
             tm.assert_numpy_array_equal(s.index.values, exp)
 
+    def test_rename_axis_supported(self):
+        # Supporting axis for compatibility, detailed in GH-18589
+        s = Series(range(5))
+        s.rename({}, axis=0)
+        s.rename({}, axis='index')
+        with tm.assert_raises_regex(ValueError, 'No axis named 5'):
+            s.rename({}, axis=5)
+
     def test_set_name_attribute(self):
         s = Series([1, 2, 3])
         s2 = Series([1, 2, 3], name='bar')