@@ -753,7 +753,7 @@ def rename_axis(self, mapper, axis=0, copy=True, inplace=False):
753753
754754 Returns
755755 -------
756- renamed : type of caller
756+ renamed : type of caller or None if inplace=True
757757
758758 See Also
759759 --------
@@ -784,27 +784,31 @@ def rename_axis(self, mapper, axis=0, copy=True, inplace=False):
784784 non_mapper = is_scalar (mapper ) or (is_list_like (mapper ) and not
785785 is_dict_like (mapper ))
786786 if non_mapper :
787- return self ._set_axis_name (mapper , axis = axis )
787+ return self ._set_axis_name (mapper , axis = axis , inplace = inplace )
788788 else :
789789 axis = self ._get_axis_name (axis )
790790 d = {'copy' : copy , 'inplace' : inplace }
791791 d [axis ] = mapper
792792 return self .rename (** d )
793793
794- def _set_axis_name (self , name , axis = 0 ):
794+ def _set_axis_name (self , name , axis = 0 , inplace = False ):
795795 """
796- Alter the name or names of the axis, returning self .
796+ Alter the name or names of the axis.
797797
798798 Parameters
799799 ----------
800800 name : str or list of str
801801 Name for the Index, or list of names for the MultiIndex
802802 axis : int or str
803803 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
804808
805809 Returns
806810 -------
807- renamed : type of caller
811+ renamed : type of caller or None if inplace=True
808812
809813 See Also
810814 --------
@@ -831,9 +835,11 @@ def _set_axis_name(self, name, axis=0):
831835 axis = self ._get_axis_number (axis )
832836 idx = self ._get_axis (axis ).set_names (name )
833837
834- renamed = self .copy (deep = True )
838+ inplace = validate_bool_kwarg (inplace , 'inplace' )
839+ renamed = self if inplace else self .copy ()
835840 renamed .set_axis (axis , idx )
836- return renamed
841+ if not inplace :
842+ return renamed
837843
838844 # ----------------------------------------------------------------------
839845 # Comparisons
0 commit comments