Skip to content

Commit a3ff79e

Browse files
committed
Revert "use S2 python/mypy#19182"
This reverts commit 1c0f351.
1 parent 1c0f351 commit a3ff79e

File tree

2 files changed

+28
-43
lines changed

2 files changed

+28
-43
lines changed

pandas-stubs/_typing.pyi

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -824,8 +824,30 @@ MaskType: TypeAlias = Series[bool] | np_ndarray_bool | list[bool]
824824

825825
# Scratch types for generics
826826

827-
SeriesDType: TypeAlias = (
828-
str
827+
S1 = TypeVar(
828+
"S1",
829+
bound=str
830+
| bytes
831+
| datetime.date
832+
| datetime.time
833+
| bool
834+
| int
835+
| float
836+
| complex
837+
| Dtype
838+
| datetime.datetime # includes pd.Timestamp
839+
| datetime.timedelta # includes pd.Timedelta
840+
| Period
841+
| Interval
842+
| CategoricalDtype
843+
| BaseOffset
844+
| list[str],
845+
default=Any,
846+
)
847+
848+
S2 = TypeVar(
849+
"S2",
850+
bound=str
829851
| bytes
830852
| datetime.date
831853
| datetime.time
@@ -840,11 +862,8 @@ SeriesDType: TypeAlias = (
840862
| Interval
841863
| CategoricalDtype
842864
| BaseOffset
843-
| list[str]
865+
| list[str],
844866
)
845-
S1 = TypeVar("S1", bound=SeriesDType, default=Any)
846-
# Like S1, but without `default=Any`.
847-
S2 = TypeVar("S2", bound=SeriesDType)
848867

849868
IndexingInt: TypeAlias = (
850869
int | np.int_ | np.integer | np.unsignedinteger | np.signedinteger | np.int8

pandas-stubs/core/frame.pyi

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ from pandas._typing import (
136136
ScalarT,
137137
SequenceNotStr,
138138
SeriesByT,
139-
SeriesDType,
140139
SortKind,
141140
StataDateFormat,
142141
StorageOptions,
@@ -1392,23 +1391,13 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
13921391
@overload
13931392
def apply(
13941393
self,
1395-
f: Callable[..., S2],
1394+
f: Callable[..., S2 | NAType],
13961395
axis: AxisIndex = ...,
13971396
raw: _bool = ...,
13981397
result_type: None = ...,
13991398
args: Any = ...,
14001399
**kwargs: Any,
14011400
) -> 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: ...
14121401
# Since non-scalar type T is not supported in Series[T],
14131402
# we separate this overload from the above one
14141403
@overload
@@ -1426,7 +1415,7 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14261415
@overload
14271416
def apply(
14281417
self,
1429-
f: Callable[..., S2],
1418+
f: Callable[..., S2 | NAType],
14301419
axis: Axis = ...,
14311420
raw: _bool = ...,
14321421
args: Any = ...,
@@ -1435,17 +1424,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14351424
**kwargs: Any,
14361425
) -> Series[S2]: ...
14371426
@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
14491427
def apply(
14501428
self,
14511429
f: Callable[..., ListLikeExceptSeriesAndStr | Series | Mapping[Any, Any]],
@@ -1495,11 +1473,10 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
14951473
) -> Series: ...
14961474

14971475
# 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.
14991476
@overload
15001477
def apply(
15011478
self,
1502-
f: Callable[..., S2],
1479+
f: Callable[..., S2 | NAType],
15031480
raw: _bool = ...,
15041481
result_type: None = ...,
15051482
args: Any = ...,
@@ -1508,17 +1485,6 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
15081485
**kwargs: Any,
15091486
) -> Series[S2]: ...
15101487
@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
15221488
def apply(
15231489
self,
15241490
f: Callable[..., ListLikeExceptSeriesAndStr | Mapping[Any, Any]],

0 commit comments

Comments
 (0)