@@ -136,6 +136,7 @@ from pandas._typing import (
136136 ScalarT ,
137137 SequenceNotStr ,
138138 SeriesByT ,
139+ SeriesDType ,
139140 SortKind ,
140141 StataDateFormat ,
141142 StorageOptions ,
@@ -1391,13 +1392,23 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13911392 @overload
13921393 def apply (
13931394 self ,
1394- f : Callable [..., S2 | NAType ],
1395+ f : Callable [..., S2 ],
13951396 axis : AxisIndex = ...,
13961397 raw : _bool = ...,
13971398 result_type : None = ...,
13981399 args : Any = ...,
13991400 ** kwargs : Any ,
14001401 ) -> 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 : ...
14011412 # Since non-scalar type T is not supported in Series[T],
14021413 # we separate this overload from the above one
14031414 @overload
@@ -1415,7 +1426,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14151426 @overload
14161427 def apply (
14171428 self ,
1418- f : Callable [..., S2 | NAType ],
1429+ f : Callable [..., S2 ],
14191430 axis : Axis = ...,
14201431 raw : _bool = ...,
14211432 args : Any = ...,
@@ -1424,6 +1435,17 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14241435 ** kwargs : Any ,
14251436 ) -> Series [S2 ]: ...
14261437 @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
14271449 def apply (
14281450 self ,
14291451 f : Callable [..., ListLikeExceptSeriesAndStr | Series | Mapping [Any , Any ]],
@@ -1473,10 +1495,11 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14731495 ) -> Series : ...
14741496
14751497 # 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.
14761499 @overload
14771500 def apply (
14781501 self ,
1479- f : Callable [..., S2 | NAType ],
1502+ f : Callable [..., S2 ],
14801503 raw : _bool = ...,
14811504 result_type : None = ...,
14821505 args : Any = ...,
@@ -1485,6 +1508,17 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14851508 ** kwargs : Any ,
14861509 ) -> Series [S2 ]: ...
14871510 @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
14881522 def apply (
14891523 self ,
14901524 f : Callable [..., ListLikeExceptSeriesAndStr | Mapping [Any , Any ]],
0 commit comments