@@ -1209,7 +1209,8 @@ class name
1209
1209
axes , kwargs = self ._construct_axes_from_arguments (
1210
1210
(), kwargs , sentinel = lib .no_default
1211
1211
)
1212
- copy = kwargs .pop ("copy" , True )
1212
+ copy : bool_t | None = kwargs .pop ("copy" , None )
1213
+
1213
1214
inplace = kwargs .pop ("inplace" , False )
1214
1215
axis = kwargs .pop ("axis" , 0 )
1215
1216
if axis is not None :
@@ -1229,7 +1230,9 @@ class name
1229
1230
is_list_like (mapper ) and not is_dict_like (mapper )
1230
1231
)
1231
1232
if non_mapper :
1232
- return self ._set_axis_name (mapper , axis = axis , inplace = inplace )
1233
+ return self ._set_axis_name (
1234
+ mapper , axis = axis , inplace = inplace , copy = copy
1235
+ )
1233
1236
else :
1234
1237
raise ValueError ("Use `.rename` to alter labels with a mapper." )
1235
1238
else :
@@ -1248,13 +1251,15 @@ class name
1248
1251
f = common .get_rename_function (v )
1249
1252
curnames = self ._get_axis (axis ).names
1250
1253
newnames = [f (name ) for name in curnames ]
1251
- result ._set_axis_name (newnames , axis = axis , inplace = True )
1254
+ result ._set_axis_name (newnames , axis = axis , inplace = True , copy = copy )
1252
1255
if not inplace :
1253
1256
return result
1254
1257
return None
1255
1258
1256
1259
@final
1257
- def _set_axis_name (self , name , axis : Axis = 0 , inplace : bool_t = False ):
1260
+ def _set_axis_name (
1261
+ self , name , axis : Axis = 0 , inplace : bool_t = False , copy : bool_t | None = True
1262
+ ):
1258
1263
"""
1259
1264
Set the name(s) of the axis.
1260
1265
@@ -1267,6 +1272,8 @@ def _set_axis_name(self, name, axis: Axis = 0, inplace: bool_t = False):
1267
1272
and the value 1 or 'columns' specifies columns.
1268
1273
inplace : bool, default False
1269
1274
If `True`, do operation inplace and return None.
1275
+ copy:
1276
+ Whether to make a copy of the result.
1270
1277
1271
1278
Returns
1272
1279
-------
@@ -1308,7 +1315,7 @@ def _set_axis_name(self, name, axis: Axis = 0, inplace: bool_t = False):
1308
1315
idx = self ._get_axis (axis ).set_names (name )
1309
1316
1310
1317
inplace = validate_bool_kwarg (inplace , "inplace" )
1311
- renamed = self if inplace else self .copy ()
1318
+ renamed = self if inplace else self .copy (deep = copy )
1312
1319
if axis == 0 :
1313
1320
renamed .index = idx
1314
1321
else :
0 commit comments