pandas-stubs icon indicating copy to clipboard operation
pandas-stubs copied to clipboard

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

Open phofl opened this issue 3 years ago • 3 comments

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 avatar Nov 29 '22 13:11 phofl

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.

gandhis1 avatar Nov 29 '22 13:11 gandhis1

Thanks!

phofl avatar Nov 29 '22 13:11 phofl

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.

gandhis1 avatar Dec 05 '22 17:12 gandhis1