-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
Type args
and kwargs
in pipe
#823
Conversation
Started out typing out frame's tests/test_frame.py:1393: error: Expression is of type <nothing>, not "DataFrame" [assert-type]
tests/test_frame.py:1394: error: Argument 1 to "pipe" of "DataFrame" has incompatible type "Callable[[DataFrame, int, str], DataFrame]"; expected "Callable[[DataFrame, int, str], <nothing>] | tuple[Callable[..., <nothing>], str]" [arg-type] Looking into this! |
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.
There is an issue here with respect to having pipe
defined in core/frame.pyi
and core/series.pyi
. I think if you took the concept proposed in this PR and used it in generic.pyi
and removed it from core/frame.pyi
, things would work for both Series
and DataFrame
.
So can you make that change, and then have tests for both Series.pipe()
and DataFrame.pipe()
?
Got it, that sounds good to me! |
Just to try things out, implemented the more complicated function with positional-only args, keyword-only args, etc. This fails in current tests. tests/test_frame.py:1401: error: Expression is of type <nothing>, not "DataFrame" [assert-type]
tests/test_frame.py:1403: error: Argument 1 to "pipe" of "DataFrame" has incompatible type "Callable[[DataFrame, int, list[float], str, NamedArg(tuple[int, int], 'keyword_only')], DataFrame]"; expected "Callable[[DataFrame, int, list[float], str, tuple[int, int]], <nothing>] | tuple[Callable[..., <nothing>], str]" [arg-type]
Found 2 errors in 1 file (checked 224 source files) However, when I upgrade mypy to latest version (1.7.1), the test does pass. However, it also raises a bunch of new errors elsewhere in code, I think all of them are of now unused mypy 1.7.1 errors
So in order to implement this I'm thinking we need to:
Happy to attempt this in another PR first if this is something we are interested in. Trying this out still in the |
Main uses mypy 1.7.1 now, so you can just rebase/merge and all the mypy warnings should disappear. |
07fc875
to
4fb7876
Compare
Cool, rebased on top of the latest changes and things mostly seem to pass. Added a lot of tests for I have some local failures right now on: 1. pytest
2. pyright
I think they're unrelated to these changes, but I'll switch back to main to check if they pass locally on my machine later before proceeding with the rest of the changes. |
15bbd54
to
19a230b
Compare
Ok, seems that test that are current failing on pyright and pytest were failing in the commit prior to mine, so I'm going to ignore those. I've completed tests for frame and implementation. I plan to just do one more thing from here: add tests for pipe to |
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 all looks pretty good. Can you add tests in test_series.py
as well similar to what you have for test_frame.py
?
Added tests in Now that it seems like will make |
Yes, so make the change in your PR to use the overloads (as in the example at microsoft/pyright#6796 (comment) ), and you might get a failure in the tests if you don't include an We probably will have to wait until 12/26 or later to get this all done. |
f4807a9
to
abc5748
Compare
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.
Thanks @paw-lu
GroupBy.pipe()
missing types in arguments and correct return type #738assert_type()
to assert the type of any return valueFollow up to pandas-dev/pandas#56359. Type out
args
andkwargs
inpipe
methods, and make all instances of thepipe
method consistent in their typing ( #738).