Skip to content

Conversation

@hamdanal
Copy link
Contributor

  • Tests added (Please use assert_type() to assert the type of any return value)

na_action default to None

Copy link
Contributor

@cmp0xff cmp0xff left a 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.

@hamdanal
Copy link
Contributor Author

Looks like the overloads are not actually needed. I simplified the stub and added the tests you suggested.

@cmp0xff
Copy link
Contributor

cmp0xff commented Nov 30, 2025

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: float64

The first case is pd.Series[int] becoming pd.Series[Any]. The second case is pd.Series[Any] becoming pd.Series[float]. Could you include them in the test?

@hamdanal
Copy link
Contributor Author

hamdanal commented Dec 7, 2025

The first case is pd.Series[int] becoming pd.Series[Any].

pyright thinks it is pd.Series[str | float], mypy pd.Series[Any] but this is the same on main so I will not work on it here

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]"
Copy link
Contributor

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.

Comment on lines +3731 to +3732
unknown_series.map({1: True, 0: False, None: None}, na_action="ignore"),
"pd.Series[bool]",
Copy link
Contributor

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],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
arg: Callable[[Any], object] | Mapping[Any, object] | Series[Any],
arg: Callable[[Any], Any] | Mapping[Any, Any] | Series,
  1. Currently we prefer Any over object to denote "arbitrary" types
  2. Series defaults to Series[Any], because S1 defaults to Any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants