@@ -59,6 +59,8 @@ from pandas._typing import (
59
59
Axes ,
60
60
Axis ,
61
61
AxisType ,
62
+ AxisTypeColumn ,
63
+ AxisTypeIndex ,
62
64
CalculationMethod ,
63
65
ColspaceArgType ,
64
66
CompressionOptions ,
@@ -1087,11 +1089,13 @@ class DataFrame(NDFrame, OpsMixin):
1087
1089
* args ,
1088
1090
** kwargs ,
1089
1091
) -> DataFrame : ...
1092
+
1093
+ # First set of apply() overloads is with defaults
1090
1094
@overload
1091
1095
def apply (
1092
1096
self ,
1093
1097
f : Callable [..., ListLikeExceptSeriesAndStr ],
1094
- axis : AxisType = ...,
1098
+ axis : AxisTypeIndex = ...,
1095
1099
raw : _bool = ...,
1096
1100
result_type : Literal [None ] = ...,
1097
1101
args = ...,
@@ -1101,7 +1105,7 @@ class DataFrame(NDFrame, OpsMixin):
1101
1105
def apply (
1102
1106
self ,
1103
1107
f : Callable [..., Series ],
1104
- axis : AxisType = ...,
1108
+ axis : AxisTypeIndex = ...,
1105
1109
raw : _bool = ...,
1106
1110
result_type : Literal [None ] = ...,
1107
1111
args = ...,
@@ -1111,17 +1115,19 @@ class DataFrame(NDFrame, OpsMixin):
1111
1115
def apply (
1112
1116
self ,
1113
1117
f : Callable [..., Scalar ],
1114
- axis : AxisType = ...,
1118
+ axis : AxisTypeIndex = ...,
1115
1119
raw : _bool = ...,
1116
1120
result_type : Literal [None ] = ...,
1117
1121
args = ...,
1118
1122
** kwargs ,
1119
1123
) -> Series : ...
1124
+
1125
+ # Second set of apply() overloads is with keyword result_type
1120
1126
@overload
1121
1127
def apply (
1122
1128
self ,
1123
1129
f : Callable [..., ListLikeExceptSeriesAndStr ],
1124
- axis : AxisType = ...,
1130
+ axis : AxisTypeIndex = ...,
1125
1131
raw : _bool = ...,
1126
1132
args = ...,
1127
1133
* ,
@@ -1132,7 +1138,7 @@ class DataFrame(NDFrame, OpsMixin):
1132
1138
def apply (
1133
1139
self ,
1134
1140
f : Callable [..., ListLikeExceptSeriesAndStr | Series ],
1135
- axis : AxisType = ...,
1141
+ axis : AxisTypeIndex = ...,
1136
1142
raw : _bool = ...,
1137
1143
args = ...,
1138
1144
* ,
@@ -1143,13 +1149,118 @@ class DataFrame(NDFrame, OpsMixin):
1143
1149
def apply (
1144
1150
self ,
1145
1151
f : Callable [..., ListLikeExceptSeriesAndStr | Series ],
1146
- axis : AxisType = ...,
1152
+ axis : AxisTypeIndex = ...,
1147
1153
raw : _bool = ...,
1148
1154
args = ...,
1149
1155
* ,
1150
1156
result_type : Literal ["broadcast" ],
1151
1157
** kwargs ,
1152
1158
) -> DataFrame : ...
1159
+
1160
+ # Third set of apply() overloads is with keyword axis=1 only
1161
+ @overload
1162
+ def apply (
1163
+ self ,
1164
+ f : Callable [..., ListLikeExceptSeriesAndStr ],
1165
+ raw : _bool = ...,
1166
+ result_type : Literal [None ] = ...,
1167
+ args = ...,
1168
+ * ,
1169
+ axis : AxisTypeColumn ,
1170
+ ** kwargs ,
1171
+ ) -> Series : ...
1172
+ @overload
1173
+ def apply (
1174
+ self ,
1175
+ f : Callable [..., Series ],
1176
+ raw : _bool = ...,
1177
+ result_type : Literal [None ] = ...,
1178
+ args = ...,
1179
+ * ,
1180
+ axis : AxisTypeColumn ,
1181
+ ** kwargs ,
1182
+ ) -> DataFrame : ...
1183
+ @overload
1184
+ def apply (
1185
+ self ,
1186
+ f : Callable [..., Scalar ],
1187
+ raw : _bool = ...,
1188
+ result_type : Literal [None ] = ...,
1189
+ args = ...,
1190
+ * ,
1191
+ axis : AxisTypeColumn ,
1192
+ ** kwargs ,
1193
+ ) -> Series : ...
1194
+
1195
+ # Fourth set of apply() overloads is with keyword axis=1 and keyword result_type
1196
+ @overload
1197
+ def apply (
1198
+ self ,
1199
+ f : Callable [..., ListLikeExceptSeriesAndStr ],
1200
+ raw : _bool = ...,
1201
+ args = ...,
1202
+ * ,
1203
+ axis : AxisTypeColumn = ...,
1204
+ result_type : Literal [None ] = ...,
1205
+ ** kwargs ,
1206
+ ) -> Series : ...
1207
+ @overload
1208
+ def apply (
1209
+ self ,
1210
+ f : Callable [..., Series ],
1211
+ raw : _bool = ...,
1212
+ args = ...,
1213
+ * ,
1214
+ axis : AxisTypeColumn = ...,
1215
+ result_type : Literal [None ] = ...,
1216
+ ** kwargs ,
1217
+ ) -> DataFrame : ...
1218
+ @overload
1219
+ def apply (
1220
+ self ,
1221
+ f : Callable [..., Scalar ],
1222
+ raw : _bool = ...,
1223
+ args = ...,
1224
+ * ,
1225
+ axis : AxisTypeColumn = ...,
1226
+ result_type : Literal [None ] = ...,
1227
+ ** kwargs ,
1228
+ ) -> Series : ...
1229
+ @overload
1230
+ def apply (
1231
+ self ,
1232
+ f : Callable [..., ListLikeExceptSeriesAndStr ],
1233
+ raw : _bool = ...,
1234
+ args = ...,
1235
+ * ,
1236
+ axis : AxisTypeColumn = ...,
1237
+ result_type : Literal ["reduce" ],
1238
+ ** kwargs ,
1239
+ ) -> Series : ...
1240
+ @overload
1241
+ def apply (
1242
+ self ,
1243
+ f : Callable [..., ListLikeExceptSeriesAndStr | Series ],
1244
+ raw : _bool = ...,
1245
+ args = ...,
1246
+ * ,
1247
+ axis : AxisTypeColumn = ...,
1248
+ result_type : Literal ["expand" ],
1249
+ ** kwargs ,
1250
+ ) -> DataFrame : ...
1251
+ @overload
1252
+ def apply (
1253
+ self ,
1254
+ f : Callable [..., ListLikeExceptSeriesAndStr | Series ],
1255
+ raw : _bool = ...,
1256
+ args = ...,
1257
+ * ,
1258
+ axis : AxisTypeColumn = ...,
1259
+ result_type : Literal ["broadcast" ],
1260
+ ** kwargs ,
1261
+ ) -> DataFrame : ...
1262
+
1263
+ # Add spacing between apply() overloads and remaining annotations
1153
1264
def applymap (
1154
1265
self , func : Callable , na_action : Literal ["ignore" ] | None = ..., ** kwargs
1155
1266
) -> DataFrame : ...
0 commit comments