Skip to content

Commit 411f2de

Browse files
Fix signature of Series.map()
1 parent 56ddb6f commit 411f2de

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

pandas-stubs/_typing.pyi

+19
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,25 @@ S1 = TypeVar(
549549
| BaseOffset,
550550
)
551551

552+
S2 = TypeVar(
553+
"S2",
554+
bound=str
555+
| bytes
556+
| datetime.date
557+
| datetime.time
558+
| bool
559+
| int
560+
| float
561+
| complex
562+
| Dtype
563+
| datetime.datetime # includes pd.Timestamp
564+
| datetime.timedelta # includes pd.Timedelta
565+
| Period
566+
| Interval
567+
| CategoricalDtype
568+
| BaseOffset,
569+
)
570+
552571
IndexingInt: TypeAlias = (
553572
int | np.int_ | np.integer | np.unsignedinteger | np.signedinteger | np.int8
554573
)

pandas-stubs/core/series.pyi

+13-1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ from pandas._libs.tslibs import BaseOffset
9393
from pandas._libs.tslibs.nattype import NaTType
9494
from pandas._typing import (
9595
S1,
96+
S2,
9697
AggFuncTypeBase,
9798
AggFuncTypeDictFrame,
9899
AggFuncTypeSeriesToFrame,
@@ -913,7 +914,18 @@ class Series(IndexOpsMixin[S1], NDFrame):
913914
level: Level = ...,
914915
fill_value: int | _str | dict | None = ...,
915916
) -> DataFrame: ...
916-
def map(self, arg, na_action: Literal["ignore"] | None = ...) -> Series[S1]: ...
917+
@overload
918+
def map(
919+
self,
920+
arg: Callable[[S1], S2 | NAType] | Mapping[S1, S2] | Series[S2],
921+
na_action: Literal["ignore"] = ...,
922+
) -> Series[S2]: ...
923+
@overload
924+
def map(
925+
self,
926+
arg: Callable[[S1 | NAType], S2 | NAType] | Mapping[S1, S2] | Series[S2],
927+
na_action: None = ...,
928+
) -> Series[S2]: ...
917929
@overload
918930
def aggregate( # type: ignore[overload-overlap]
919931
self: Series[int],

0 commit comments

Comments
 (0)