-
-
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?
Conversation
cmp0xff
left a comment
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.
I tried your idea myself and found one more unaddressed case.
|
Looks like the overloads are not actually needed. I simplified the stub and added the tests you suggested. |
Removing the overloads is a bit alerting. I've come up with the following examples. >>> import pandas as pd
>>> pd.Series([1, 2, 3]).map({1: "a", 2: 1.5})
0 a
1 1.5
2 NaN
dtype: object
>>> pd.Series([1, "a"]).map({1: 1.0, "a": 2.0})
0 1.0
1 2.0
dtype: float64The first case is |
pyright thinks it is |
| 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]" |
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.
This is not a good behaviour, because unknown_series.map({1: True, 0: False, None: None}) gives dtype=object at runtime. We would like to have Series[Any] in such case.
| unknown_series.map({1: True, 0: False, None: None}, na_action="ignore"), | ||
| "pd.Series[bool]", |
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.
unknown_series.map({1: True, 0: False, None: None}, na_action="ignore") also gives dtype=object at runtime. We would like to have Series[Any] in such case.
| self, | ||
| arg: Callable[[Any], Any] | Mapping[Any, Any] | Series, | ||
| na_action: Literal["ignore"] | None = ..., | ||
| arg: Callable[[Any], object] | Mapping[Any, object] | Series[Any], |
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.
| arg: Callable[[Any], object] | Mapping[Any, object] | Series[Any], | |
| arg: Callable[[Any], Any] | Mapping[Any, Any] | Series, |
- Currently we prefer
Anyoverobjectto denote "arbitrary" types Seriesdefaults toSeries[Any], becauseS1defaults toAny.
assert_type()to assert the type of any return value)na_actiondefault toNone