@@ -136,6 +136,7 @@ from pandas._typing import (
136
136
ScalarT ,
137
137
SequenceNotStr ,
138
138
SeriesByT ,
139
+ SeriesDType ,
139
140
SortKind ,
140
141
StataDateFormat ,
141
142
StorageOptions ,
@@ -1391,13 +1392,23 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1391
1392
@overload
1392
1393
def apply (
1393
1394
self ,
1394
- f : Callable [..., S2 | NAType ],
1395
+ f : Callable [..., S2 ],
1395
1396
axis : AxisIndex = ...,
1396
1397
raw : _bool = ...,
1397
1398
result_type : None = ...,
1398
1399
args : Any = ...,
1399
1400
** kwargs : Any ,
1400
1401
) -> Series [S2 ]: ...
1402
+ @overload
1403
+ def apply (
1404
+ self ,
1405
+ f : Callable [..., SeriesDType | NAType ],
1406
+ axis : AxisIndex = ...,
1407
+ raw : _bool = ...,
1408
+ result_type : None = ...,
1409
+ args : Any = ...,
1410
+ ** kwargs : Any ,
1411
+ ) -> Series : ...
1401
1412
# Since non-scalar type T is not supported in Series[T],
1402
1413
# we separate this overload from the above one
1403
1414
@overload
@@ -1415,7 +1426,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1415
1426
@overload
1416
1427
def apply (
1417
1428
self ,
1418
- f : Callable [..., S2 | NAType ],
1429
+ f : Callable [..., S2 ],
1419
1430
axis : Axis = ...,
1420
1431
raw : _bool = ...,
1421
1432
args : Any = ...,
@@ -1424,6 +1435,17 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1424
1435
** kwargs : Any ,
1425
1436
) -> Series [S2 ]: ...
1426
1437
@overload
1438
+ def apply (
1439
+ self ,
1440
+ f : Callable [..., SeriesDType | NAType ],
1441
+ axis : Axis = ...,
1442
+ raw : _bool = ...,
1443
+ args : Any = ...,
1444
+ * ,
1445
+ result_type : Literal ["expand" , "reduce" ],
1446
+ ** kwargs : Any ,
1447
+ ) -> Series : ...
1448
+ @overload
1427
1449
def apply (
1428
1450
self ,
1429
1451
f : Callable [..., ListLikeExceptSeriesAndStr | Series | Mapping [Any , Any ]],
@@ -1473,10 +1495,11 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1473
1495
) -> Series : ...
1474
1496
1475
1497
# apply() overloads with default result_type of None, and keyword axis=1 matters
1498
+ # Use S2 (TypeVar without the `Any` default) to avoid MyPy issue https://github.com/python/mypy/issues/19182.
1476
1499
@overload
1477
1500
def apply (
1478
1501
self ,
1479
- f : Callable [..., S2 | NAType ],
1502
+ f : Callable [..., S2 ],
1480
1503
raw : _bool = ...,
1481
1504
result_type : None = ...,
1482
1505
args : Any = ...,
@@ -1485,6 +1508,17 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
1485
1508
** kwargs : Any ,
1486
1509
) -> Series [S2 ]: ...
1487
1510
@overload
1511
+ def apply (
1512
+ self ,
1513
+ f : Callable [..., SeriesDType | NAType ],
1514
+ raw : _bool = ...,
1515
+ result_type : None = ...,
1516
+ args : Any = ...,
1517
+ * ,
1518
+ axis : AxisColumn ,
1519
+ ** kwargs : Any ,
1520
+ ) -> Series : ...
1521
+ @overload
1488
1522
def apply (
1489
1523
self ,
1490
1524
f : Callable [..., ListLikeExceptSeriesAndStr | Mapping [Any , Any ]],
0 commit comments