-
-
Notifications
You must be signed in to change notification settings - Fork 154
Fix Series.map default for na_action
#1510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
14f610c
00baef9
654d505
b672627
4764c07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3700,6 +3700,7 @@ def test_map() -> None: | |
| pd.Series, | ||
| str, | ||
| ) | ||
| check(assert_type(s.map(mapping), "pd.Series[str]"), pd.Series, str) | ||
|
|
||
| def callable(x: int) -> str: | ||
| return str(x) | ||
|
|
@@ -3709,16 +3710,35 @@ def callable(x: int) -> str: | |
| pd.Series, | ||
| str, | ||
| ) | ||
| check(assert_type(s.map(callable), "pd.Series[str]"), pd.Series, str) | ||
|
|
||
| series = pd.Series(["a", "b", "c"]) | ||
| check( | ||
| assert_type(s.map(series, na_action="ignore"), "pd.Series[str]"), pd.Series, str | ||
| ) | ||
| check(assert_type(s.map(series), "pd.Series[str]"), pd.Series, str) | ||
|
|
||
| unknown_series = pd.Series([1, 0, None]) | ||
| check( | ||
| assert_type(unknown_series.map({1: True, 0: False, None: None}), pd.Series), | ||
| assert_type( | ||
| unknown_series.map({1: True, 0: False, None: None}), "pd.Series[bool]" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a good behaviour, because |
||
| ), | ||
| pd.Series, | ||
| bool, | ||
| ) | ||
| check( | ||
| assert_type( | ||
| unknown_series.map({1: True, 0: False, None: None}, na_action="ignore"), | ||
| "pd.Series[bool]", | ||
|
Comment on lines
+3731
to
+3732
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ), | ||
| pd.Series, | ||
| bool, | ||
| ) | ||
| s_mixed = pd.Series([1, "a"]) | ||
| check( | ||
| assert_type(s_mixed.map({1: 1.0, "a": 2.0}), "pd.Series[float]"), | ||
| pd.Series, | ||
| float, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -3736,10 +3756,22 @@ def callable(x: int | NAType) -> str | NAType: | |
| check( | ||
| assert_type(s.map(callable, na_action=None), "pd.Series[str]"), pd.Series, str | ||
| ) | ||
| # na_action defaults to None | ||
| check(assert_type(s.map(callable), "pd.Series[str]"), pd.Series, str) | ||
|
|
||
| series = pd.Series(["a", "b", "c"]) | ||
| check(assert_type(s.map(series, na_action=None), "pd.Series[str]"), pd.Series, str) | ||
|
|
||
| def callable2(x: int | NAType | None) -> str | None: | ||
| if isinstance(x, int): | ||
| return str(x) | ||
| return None | ||
|
|
||
| check( | ||
| assert_type(s.map(callable2, na_action=None), "pd.Series[str]"), pd.Series, str | ||
| ) | ||
| check(assert_type(s.map(callable2), "pd.Series[str]"), pd.Series, str) | ||
|
|
||
|
|
||
| def test_case_when() -> None: | ||
| c = pd.Series([6, 7, 8, 9], name="c") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyoverobjectto denote "arbitrary" typesSeriesdefaults toSeries[Any], becauseS1defaults toAny.