Skip to content

Commit 491801e

Browse files
AaronCritchleyharisbal
authored and
harisbal
committed
COMPAT-18589: Supporting axis in Series.rename (pandas-dev#18923)
1 parent e42b61f commit 491801e

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

doc/source/whatsnew/v0.23.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ Reshaping
841841
- 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`)
842842
- Improved error message for :func:`DataFrame.merge` when there is no common merge key (:issue:`19427`)
843843
- 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`)
844+
- :func:`Series.rename` now accepts ``axis`` as a kwarg (:issue:`18589`)
844845

845846
Other
846847
^^^^^

pandas/core/generic.py

+3
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,9 @@ def rename(self, *args, **kwargs):
863863
copy = kwargs.pop('copy', True)
864864
inplace = kwargs.pop('inplace', False)
865865
level = kwargs.pop('level', None)
866+
axis = kwargs.pop('axis', None)
867+
if axis is not None:
868+
axis = self._get_axis_number(axis)
866869

867870
if kwargs:
868871
raise TypeError('rename() got an unexpected keyword '

pandas/tests/series/test_alter_axes.py

+8
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ def test_rename_set_name_inplace(self):
8181
exp = np.array(['a', 'b', 'c'], dtype=np.object_)
8282
tm.assert_numpy_array_equal(s.index.values, exp)
8383

84+
def test_rename_axis_supported(self):
85+
# Supporting axis for compatibility, detailed in GH-18589
86+
s = Series(range(5))
87+
s.rename({}, axis=0)
88+
s.rename({}, axis='index')
89+
with tm.assert_raises_regex(ValueError, 'No axis named 5'):
90+
s.rename({}, axis=5)
91+
8492
def test_set_name_attribute(self):
8593
s = Series([1, 2, 3])
8694
s2 = Series([1, 2, 3], name='bar')

0 commit comments

Comments
 (0)