@@ -753,7 +753,7 @@ def rename_axis(self, mapper, axis=0, copy=True, inplace=False):
753
753
754
754
Returns
755
755
-------
756
- renamed : type of caller
756
+ renamed : type of caller or None if inplace=True
757
757
758
758
See Also
759
759
--------
@@ -784,27 +784,31 @@ def rename_axis(self, mapper, axis=0, copy=True, inplace=False):
784
784
non_mapper = is_scalar (mapper ) or (is_list_like (mapper ) and not
785
785
is_dict_like (mapper ))
786
786
if non_mapper :
787
- return self ._set_axis_name (mapper , axis = axis )
787
+ return self ._set_axis_name (mapper , axis = axis , inplace = inplace )
788
788
else :
789
789
axis = self ._get_axis_name (axis )
790
790
d = {'copy' : copy , 'inplace' : inplace }
791
791
d [axis ] = mapper
792
792
return self .rename (** d )
793
793
794
- def _set_axis_name (self , name , axis = 0 ):
794
+ def _set_axis_name (self , name , axis = 0 , inplace = False ):
795
795
"""
796
- Alter the name or names of the axis, returning self .
796
+ Alter the name or names of the axis.
797
797
798
798
Parameters
799
799
----------
800
800
name : str or list of str
801
801
Name for the Index, or list of names for the MultiIndex
802
802
axis : int or str
803
803
0 or 'index' for the index; 1 or 'columns' for the columns
804
+ inplace : bool
805
+ whether to modify `self` directly or return a copy
806
+
807
+ .. versionadded: 0.21.0
804
808
805
809
Returns
806
810
-------
807
- renamed : type of caller
811
+ renamed : type of caller or None if inplace=True
808
812
809
813
See Also
810
814
--------
@@ -831,9 +835,11 @@ def _set_axis_name(self, name, axis=0):
831
835
axis = self ._get_axis_number (axis )
832
836
idx = self ._get_axis (axis ).set_names (name )
833
837
834
- renamed = self .copy (deep = True )
838
+ inplace = validate_bool_kwarg (inplace , 'inplace' )
839
+ renamed = self if inplace else self .copy ()
835
840
renamed .set_axis (axis , idx )
836
- return renamed
841
+ if not inplace :
842
+ return renamed
837
843
838
844
# ----------------------------------------------------------------------
839
845
# Comparisons
0 commit comments