Skip to content

Commit 3fe9674

Browse files
Fix series.map overloads
1 parent e78aaca commit 3fe9674

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pandas-stubs/core/series.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ class Series(IndexOpsMixin[S1], NDFrame):
917917
def map(
918918
self,
919919
arg: Callable[[S1], S2 | NAType] | Mapping[S1, S2] | Series[S2],
920-
na_action: Literal["ignore"] = ...,
920+
na_action: Literal["ignore"],
921921
) -> Series[S2]: ...
922922
@overload
923923
def map(

tests/test_series.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,18 +3276,34 @@ def test_map_na() -> None:
32763276

32773277
mapping = {1: "a", 2: "b", 3: "c"}
32783278
check(assert_type(s.map(mapping, na_action=None), "pd.Series[str]"), pd.Series, str)
3279+
check(assert_type(s.map(mapping), "pd.Series[str]"), pd.Series, str)
32793280

32803281
def callable(x: int | NAType) -> str | NAType:
32813282
if isinstance(x, int):
32823283
return str(x)
32833284
return x
32843285

3286+
def bad_callable(x: int) -> int:
3287+
return x + 1
3288+
3289+
s.map(
3290+
bad_callable, na_action=None # type: ignore[arg-type] # pyright: ignore[reportCallIssue, reportArgumentType]
3291+
)
3292+
s.map(bad_callable) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
3293+
check(
3294+
assert_type(s.map(bad_callable, na_action="ignore"), "pd.Series[int]"),
3295+
pd.Series,
3296+
int,
3297+
)
3298+
32853299
check(
32863300
assert_type(s.map(callable, na_action=None), "pd.Series[str]"), pd.Series, str
32873301
)
3302+
check(assert_type(s.map(callable), "pd.Series[str]"), pd.Series, str)
32883303

32893304
series = pd.Series(["a", "b", "c"])
32903305
check(assert_type(s.map(series, na_action=None), "pd.Series[str]"), pd.Series, str)
3306+
check(assert_type(s.map(series), "pd.Series[str]"), pd.Series, str)
32913307

32923308

32933309
def test_case_when() -> None:

0 commit comments

Comments
 (0)