@@ -60,6 +60,8 @@ from pandas._typing import (
60
60
Axes ,
61
61
Axis ,
62
62
AxisType ,
63
+ AxisTypeColumn ,
64
+ AxisTypeIndex ,
63
65
CalculationMethod ,
64
66
ColspaceArgType ,
65
67
CompressionOptions ,
@@ -83,6 +85,7 @@ from pandas._typing import (
83
85
Label ,
84
86
Level ,
85
87
ListLike ,
88
+ ListLikeExceptSeriesAndStr ,
86
89
ListLikeU ,
87
90
MaskType ,
88
91
MergeHow ,
@@ -1085,36 +1088,137 @@ class DataFrame(NDFrame, OpsMixin):
1085
1088
* args ,
1086
1089
** kwargs ,
1087
1090
) -> DataFrame : ...
1091
+
1092
+ # apply() overloads with default result_type of None, and is indifferent to axis
1088
1093
@overload
1089
1094
def apply (
1090
1095
self ,
1091
- f : Callable [..., Series ],
1096
+ f : Callable [..., ListLikeExceptSeriesAndStr | Series ],
1097
+ axis : AxisTypeIndex = ...,
1098
+ raw : _bool = ...,
1099
+ result_type : Literal [None ] = ...,
1100
+ args = ...,
1101
+ ** kwargs ,
1102
+ ) -> DataFrame : ...
1103
+ @overload
1104
+ def apply (
1105
+ self ,
1106
+ f : Callable [..., S1 ],
1107
+ axis : AxisTypeIndex = ...,
1108
+ raw : _bool = ...,
1109
+ result_type : Literal [None ] = ...,
1110
+ args = ...,
1111
+ ** kwargs ,
1112
+ ) -> Series [S1 ]: ...
1113
+
1114
+ # apply() overloads with keyword result_type, and axis does not matter
1115
+ @overload
1116
+ def apply (
1117
+ self ,
1118
+ f : Callable [..., S1 ],
1119
+ axis : AxisType = ...,
1120
+ raw : _bool = ...,
1121
+ args = ...,
1122
+ * ,
1123
+ result_type : Literal ["expand" , "reduce" ],
1124
+ ** kwargs ,
1125
+ ) -> Series [S1 ]: ...
1126
+ @overload
1127
+ def apply (
1128
+ self ,
1129
+ f : Callable [..., ListLikeExceptSeriesAndStr | Series ],
1092
1130
axis : AxisType = ...,
1093
1131
raw : _bool = ...,
1094
- result_type : Literal ["expand" , "reduce" , "broadcast" ] | None = ...,
1095
1132
args = ...,
1133
+ * ,
1134
+ result_type : Literal ["expand" ],
1096
1135
** kwargs ,
1097
1136
) -> DataFrame : ...
1098
1137
@overload
1099
1138
def apply (
1100
1139
self ,
1101
- f : Callable [..., Scalar ],
1140
+ f : Callable [..., ListLikeExceptSeriesAndStr ],
1102
1141
axis : AxisType = ...,
1103
1142
raw : _bool = ...,
1104
- result_type : Literal ["expand" , "reduce" ] | None = ...,
1105
1143
args = ...,
1144
+ * ,
1145
+ result_type : Literal ["reduce" ],
1106
1146
** kwargs ,
1107
1147
) -> Series : ...
1108
1148
@overload
1109
1149
def apply (
1110
1150
self ,
1111
- f : Callable [..., Scalar ],
1112
- result_type : Literal ["broadcast" ],
1151
+ f : Callable [..., ListLikeExceptSeriesAndStr | Series | Scalar ],
1113
1152
axis : AxisType = ...,
1114
1153
raw : _bool = ...,
1115
1154
args = ...,
1155
+ * ,
1156
+ result_type : Literal ["broadcast" ],
1116
1157
** kwargs ,
1117
1158
) -> DataFrame : ...
1159
+
1160
+ # apply() overloads with keyword result_type, and axis does matter
1161
+ @overload
1162
+ def apply (
1163
+ self ,
1164
+ f : Callable [..., Series ],
1165
+ axis : AxisTypeIndex = ...,
1166
+ raw : _bool = ...,
1167
+ args = ...,
1168
+ * ,
1169
+ result_type : Literal ["reduce" ],
1170
+ ** kwargs ,
1171
+ ) -> Series : ...
1172
+
1173
+ # apply() overloads with default result_type of None, and keyword axis=1 matters
1174
+ @overload
1175
+ def apply (
1176
+ self ,
1177
+ f : Callable [..., S1 ],
1178
+ raw : _bool = ...,
1179
+ result_type : Literal [None ] = ...,
1180
+ args = ...,
1181
+ * ,
1182
+ axis : AxisTypeColumn ,
1183
+ ** kwargs ,
1184
+ ) -> Series [S1 ]: ...
1185
+ @overload
1186
+ def apply (
1187
+ self ,
1188
+ f : Callable [..., ListLikeExceptSeriesAndStr ],
1189
+ raw : _bool = ...,
1190
+ result_type : Literal [None ] = ...,
1191
+ args = ...,
1192
+ * ,
1193
+ axis : AxisTypeColumn ,
1194
+ ** kwargs ,
1195
+ ) -> Series : ...
1196
+ @overload
1197
+ def apply (
1198
+ self ,
1199
+ f : Callable [..., Series ],
1200
+ raw : _bool = ...,
1201
+ result_type : Literal [None ] = ...,
1202
+ args = ...,
1203
+ * ,
1204
+ axis : AxisTypeColumn ,
1205
+ ** kwargs ,
1206
+ ) -> DataFrame : ...
1207
+
1208
+ # apply() overloads with keyword axis=1 and keyword result_type
1209
+ @overload
1210
+ def apply (
1211
+ self ,
1212
+ f : Callable [..., Series ],
1213
+ raw : _bool = ...,
1214
+ args = ...,
1215
+ * ,
1216
+ axis : AxisTypeColumn ,
1217
+ result_type : Literal ["reduce" ],
1218
+ ** kwargs ,
1219
+ ) -> DataFrame : ...
1220
+
1221
+ # Add spacing between apply() overloads and remaining annotations
1118
1222
def applymap (
1119
1223
self , func : Callable , na_action : Literal ["ignore" ] | None = ..., ** kwargs
1120
1224
) -> DataFrame : ...
0 commit comments