Skip to content

Commit

Permalink
COMPAT-18589: Supporting axis in Series.rename (pandas-dev#18923)
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronCritchley authored and harisbal committed Feb 28, 2018
1 parent e42b61f commit 491801e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ Reshaping
- Bug in :func:`concat` when concatting sparse and dense series it returns only a ``SparseDataFrame``. Should be a ``DataFrame``. (:issue:`18914`, :issue:`18686`, and :issue:`16874`)
- Improved error message for :func:`DataFrame.merge` when there is no common merge key (:issue:`19427`)
- Bug in :func:`DataFrame.join` which does an *outer* instead of a *left* join when being called with multiple DataFrames and some have non-unique indices (:issue:`19624`)
- :func:`Series.rename` now accepts ``axis`` as a kwarg (:issue:`18589`)

Other
^^^^^
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/series/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 491801e

Please sign in to comment.