@@ -488,7 +488,7 @@ def _expand_axes(self, key):
488
488
Returns
489
489
-------
490
490
renamed : %(klass)s or None
491
- New object if inplace=False, None otherwise.
491
+ An object of same type as caller if inplace=False, None otherwise.
492
492
493
493
See Also
494
494
--------
@@ -502,23 +502,23 @@ def _expand_axes(self, key):
502
502
1 2
503
503
2 3
504
504
dtype: int64
505
- >>> s.set_axis(0, ['a', 'b', 'c'], inplace=False)
505
+ >>> s.set_axis(['a', 'b', 'c'], axis=0 , inplace=False)
506
506
a 1
507
507
b 2
508
508
c 3
509
509
dtype: int64
510
510
>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
511
- >>> df.set_axis(0, ['a', 'b', 'c'], inplace=False)
511
+ >>> df.set_axis(['a', 'b', 'c'], axis=0 , inplace=False)
512
512
A B
513
513
a 1 4
514
514
b 2 5
515
515
c 3 6
516
- >>> df.set_axis(1, ['I', 'II'], inplace=False)
516
+ >>> df.set_axis(['I', 'II'], axis=1 , inplace=False)
517
517
I II
518
518
0 1 4
519
519
1 2 5
520
520
2 3 6
521
- >>> df.set_axis(1, ['i', 'ii'], inplace=True)
521
+ >>> df.set_axis(['i', 'ii'], axis=1 , inplace=True)
522
522
>>> df
523
523
i ii
524
524
0 1 4
@@ -531,18 +531,18 @@ def _expand_axes(self, key):
531
531
def set_axis (self , labels , axis = 0 , inplace = None ):
532
532
if is_scalar (labels ):
533
533
warnings .warn (
534
- " set_axis now takes \ " labels\ " as first argument, and "
535
- " \" axis\ " as named parameter. The old form, with \ " axis\ " as "
536
- " first parameter and \" labels\" as second, is still supported "
537
- " but will be deprecated in a future version of pandas." ,
534
+ ' set_axis now takes "labels" as first argument, and '
535
+ '" axis" as named parameter. The old form, with "axis" as '
536
+ ' first parameter and \" labels\" as second, is still supported '
537
+ ' but will be deprecated in a future version of pandas.' ,
538
538
FutureWarning , stacklevel = 2 )
539
539
labels , axis = axis , labels
540
540
541
541
if inplace is None :
542
542
warnings .warn (
543
- " set_axis currently defaults to operating inplace.\n This "
544
- " will change in a future version of pandas, use "
545
- " inplace=True to avoid this warning." ,
543
+ ' set_axis currently defaults to operating inplace.\n This '
544
+ ' will change in a future version of pandas, use '
545
+ ' inplace=True to avoid this warning.' ,
546
546
FutureWarning , stacklevel = 2 )
547
547
inplace = True
548
548
if inplace :
@@ -957,7 +957,7 @@ def _set_axis_name(self, name, axis=0, inplace=False):
957
957
958
958
inplace = validate_bool_kwarg (inplace , 'inplace' )
959
959
renamed = self if inplace else self .copy ()
960
- renamed .set_axis (axis , idx )
960
+ renamed .set_axis (idx , axis = axis , inplace = True )
961
961
if not inplace :
962
962
return renamed
963
963
@@ -5845,7 +5845,7 @@ def slice_shift(self, periods=1, axis=0):
5845
5845
5846
5846
new_obj = self ._slice (vslicer , axis = axis )
5847
5847
shifted_axis = self ._get_axis (axis )[islicer ]
5848
- new_obj .set_axis (axis , shifted_axis )
5848
+ new_obj .set_axis (shifted_axis , axis = axis , inplace = True )
5849
5849
5850
5850
return new_obj .__finalize__ (self )
5851
5851
@@ -6005,7 +6005,7 @@ def _tz_convert(ax, tz):
6005
6005
ax = _tz_convert (ax , tz )
6006
6006
6007
6007
result = self ._constructor (self ._data , copy = copy )
6008
- result .set_axis (axis , ax )
6008
+ result .set_axis (ax , axis = axis , inplace = True )
6009
6009
return result .__finalize__ (self )
6010
6010
6011
6011
@deprecate_kwarg (old_arg_name = 'infer_dst' , new_arg_name = 'ambiguous' ,
@@ -6073,7 +6073,7 @@ def _tz_localize(ax, tz, ambiguous):
6073
6073
ax = _tz_localize (ax , tz , ambiguous )
6074
6074
6075
6075
result = self ._constructor (self ._data , copy = copy )
6076
- result .set_axis (axis , ax )
6076
+ result .set_axis (ax , axis = axis , inplace = True )
6077
6077
return result .__finalize__ (self )
6078
6078
6079
6079
# ----------------------------------------------------------------------
0 commit comments