90
90
SettingWithCopyError ,
91
91
SettingWithCopyWarning ,
92
92
)
93
- from pandas .util ._decorators import (
94
- doc ,
95
- rewrite_axis_style_signature ,
96
- )
93
+ from pandas .util ._decorators import doc
97
94
from pandas .util ._exceptions import find_stack_level
98
95
from pandas .util ._validators import (
99
96
validate_ascending ,
@@ -509,38 +506,6 @@ def _construct_axes_dict(self, axes: Sequence[Axis] | None = None, **kwargs):
509
506
d .update (kwargs ) # type: ignore[arg-type]
510
507
return d
511
508
512
- @final
513
- @classmethod
514
- def _construct_axes_from_arguments (
515
- cls , args , kwargs , require_all : bool_t = False , sentinel = None
516
- ):
517
- """
518
- Construct and returns axes if supplied in args/kwargs.
519
-
520
- If require_all, raise if all axis arguments are not supplied
521
- return a tuple of (axes, kwargs).
522
-
523
- sentinel specifies the default parameter when an axis is not
524
- supplied; useful to distinguish when a user explicitly passes None
525
- in scenarios where None has special meaning.
526
- """
527
- # construct the args
528
- args = list (args )
529
- for a in cls ._AXIS_ORDERS :
530
-
531
- # look for a argument by position
532
- if a not in kwargs :
533
- try :
534
- kwargs [a ] = args .pop (0 )
535
- except IndexError as err :
536
- if require_all :
537
- raise TypeError (
538
- "not enough/duplicate arguments specified!"
539
- ) from err
540
-
541
- axes = {a : kwargs .pop (a , sentinel ) for a in cls ._AXIS_ORDERS }
542
- return axes , kwargs
543
-
544
509
@final
545
510
@classmethod
546
511
def _get_axis_number (cls , axis : Axis ) -> AxisInt :
@@ -1077,8 +1042,11 @@ def rename_axis(
1077
1042
self : NDFrameT ,
1078
1043
mapper : IndexLabel | lib .NoDefault = ...,
1079
1044
* ,
1045
+ index = ...,
1046
+ columns = ...,
1047
+ axis : Axis = ...,
1048
+ copy : bool_t | None = ...,
1080
1049
inplace : Literal [False ] = ...,
1081
- ** kwargs ,
1082
1050
) -> NDFrameT :
1083
1051
...
1084
1052
@@ -1087,8 +1055,11 @@ def rename_axis(
1087
1055
self ,
1088
1056
mapper : IndexLabel | lib .NoDefault = ...,
1089
1057
* ,
1058
+ index = ...,
1059
+ columns = ...,
1060
+ axis : Axis = ...,
1061
+ copy : bool_t | None = ...,
1090
1062
inplace : Literal [True ],
1091
- ** kwargs ,
1092
1063
) -> None :
1093
1064
...
1094
1065
@@ -1097,18 +1068,23 @@ def rename_axis(
1097
1068
self : NDFrameT ,
1098
1069
mapper : IndexLabel | lib .NoDefault = ...,
1099
1070
* ,
1071
+ index = ...,
1072
+ columns = ...,
1073
+ axis : Axis = ...,
1074
+ copy : bool_t | None = ...,
1100
1075
inplace : bool_t = ...,
1101
- ** kwargs ,
1102
1076
) -> NDFrameT | None :
1103
1077
...
1104
1078
1105
- @rewrite_axis_style_signature ("mapper" , [("copy" , True )])
1106
1079
def rename_axis (
1107
1080
self : NDFrameT ,
1108
1081
mapper : IndexLabel | lib .NoDefault = lib .no_default ,
1109
1082
* ,
1083
+ index = lib .no_default ,
1084
+ columns = lib .no_default ,
1085
+ axis : Axis = 0 ,
1086
+ copy : bool_t | None = None ,
1110
1087
inplace : bool_t = False ,
1111
- ** kwargs ,
1112
1088
) -> NDFrameT | None :
1113
1089
"""
1114
1090
Set the name of the axis for the index or columns.
@@ -1129,7 +1105,7 @@ def rename_axis(
1129
1105
and/or ``columns``.
1130
1106
axis : {0 or 'index', 1 or 'columns'}, default 0
1131
1107
The axis to rename. For `Series` this parameter is unused and defaults to 0.
1132
- copy : bool, default True
1108
+ copy : bool, default None
1133
1109
Also copy underlying data.
1134
1110
inplace : bool, default False
1135
1111
Modifies the object directly, instead of creating a new Series
@@ -1233,23 +1209,11 @@ class name
1233
1209
cat 4 0
1234
1210
monkey 2 2
1235
1211
"""
1236
- kwargs ["inplace" ] = inplace
1237
- axes , kwargs = self ._construct_axes_from_arguments (
1238
- (), kwargs , sentinel = lib .no_default
1239
- )
1240
- copy : bool_t | None = kwargs .pop ("copy" , None )
1212
+ axes = {"index" : index , "columns" : columns }
1241
1213
1242
- inplace = kwargs .pop ("inplace" , False )
1243
- axis = kwargs .pop ("axis" , 0 )
1244
1214
if axis is not None :
1245
1215
axis = self ._get_axis_number (axis )
1246
1216
1247
- if kwargs :
1248
- raise TypeError (
1249
- "rename_axis() got an unexpected keyword "
1250
- f'argument "{ list (kwargs .keys ())[0 ]} "'
1251
- )
1252
-
1253
1217
inplace = validate_bool_kwarg (inplace , "inplace" )
1254
1218
1255
1219
if mapper is not lib .no_default :
@@ -4530,7 +4494,9 @@ def drop(
4530
4494
axis_name = self ._get_axis_name (axis )
4531
4495
axes = {axis_name : labels }
4532
4496
elif index is not None or columns is not None :
4533
- axes , _ = self ._construct_axes_from_arguments ((index , columns ), {})
4497
+ axes = {"index" : index }
4498
+ if self .ndim == 2 :
4499
+ axes ["columns" ] = columns
4534
4500
else :
4535
4501
raise ValueError (
4536
4502
"Need to specify at least one of 'labels', 'index' or 'columns'"
0 commit comments