pandas-stubs
pandas-stubs copied to clipboard
Regression: Series.apply is too strict, does not allow to return a DateOffset
Describe the bug A clear and concise description of what the bug is.
To Reproduce
- Provide a minimal runnable
pandasexample that is not properly checked by the stubs. - Indicate which type checker you are using (
mypyorpyright). - 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-stubspandas_stubs-1.5.2.221124
Additional context Add any other context about the problem here.
This was caused by #401
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.
Thanks!
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.