Skip to content

Regression: Series.apply is too strict, does not allow to return a DateOffset #454

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

Closed
phofl opened this issue Nov 29, 2022 · 3 comments · Fixed by #1087
Closed

Regression: Series.apply is too strict, does not allow to return a DateOffset #454

phofl opened this issue Nov 29, 2022 · 3 comments · Fixed by #1087
Labels
Apply Apply, Aggregate, Transform Regression Functionality that used to work in a prior pandas version

Comments

@phofl
Copy link
Member

phofl commented Nov 29, 2022

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

  1. Provide a minimal runnable pandas example that is not properly checked by the stubs.
  2. Indicate which type checker you are using (mypy or pyright).
  3. Show the error message received from that type checker while checking your example.

Arguments and return value are both too strict:

months = [1, 2, 3]
pd.Series(months).apply(lambda x: pd.DateOffset(months=x))

returns

error: Argument 1 to "apply" of "Series" has incompatible type "Callable[[Any], DateOffset]"; expected "Callable[..., Union[str, bytes, date, timedelta, complex, Sequence[Any], Mapping[Any, Any]]]"  [arg-type]
error: Incompatible return value type (got "DateOffset", expected "Union[str, bytes, date, timedelta, complex, Sequence[Any], Mapping[Any, Any]]")  [return-value]

Please complete the following information:

  • OS: [e.g. Windows, Linux, MacOS] macOS
  • OS Version [e.g. 22] Ventura 13.01
  • python version 3.10.5
  • version of type checker mypy 0.990
  • version of installed pandas-stubs pandas_stubs-1.5.2.221124

Additional context
Add any other context about the problem here.

This was caused by #401

@phofl phofl added Apply Apply, Aggregate, Transform Regression Functionality that used to work in a prior pandas version labels Nov 29, 2022
@gandhis1
Copy link
Contributor

gandhis1 commented Nov 29, 2022

I have a PR open to address this. Will try to wrap it up later today and include this as a test case.

Edit: Actually, my frame changes may not cover series...so I'll have to take a look at that too.

@phofl
Copy link
Member Author

phofl commented Nov 29, 2022

Thanks!

brunoroque06 added a commit to brunoroque06/plays that referenced this issue Dec 3, 2022
@gandhis1
Copy link
Contributor

gandhis1 commented Dec 5, 2022

I'll take a look at this one as well. I'll basically duplicate all of the tests I wrote for DataFrame for Series - which were intended to be as exhaustive as possible - and then work backwards from there.

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