-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: DataFrame.(dot, __matmul__) #38765
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
Conversation
cc @simonjayhawkins This currently fails with mypy for reasons I haven't figured out:
but I believe what I have is the correct logic for these methods:
|
pandas/core/frame.py
Outdated
... | ||
|
||
@overload | ||
def dot(self, other: Union[DataFrame, Index, ArrayLike]) -> Optional[DataFrame]: |
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.
why is the return Optional?
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.
It's a (likely misguided) attempt to please mypy. There's no return statement after the raise at the end so technically returns None, although ofc we never get there
(I'm honestly not sure why what I have, without the optional return, isn't working - I think it should be right)
from experience, |
Thanks @arw2019 for the PR. when adding overloads also add the types to the actual method. The overloads are used by mypy when establishing the return type when checking functions with calls to this method. The typing on the actual method is used to check this method. |
…taframe-dot-overload
Right. Is it right there's no great way to fix that before Currently I added a That said, I know
Thanks, that was the problem (in addition to the |
@@ -1141,7 +1142,15 @@ def __len__(self) -> int: | |||
""" | |||
return len(self.index) | |||
|
|||
def dot(self, other): | |||
@overload |
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.
why is this ignore?
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.
i see your comment, can you make this the actual type error as a comment
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.
Done
thanks @arw2019 |
def dot(self, other: Union[DataFrame, Index, ArrayLike]) -> DataFrame: | ||
... | ||
|
||
def dot(self, other: Union[AnyArrayLike, FrameOrSeriesUnion]) -> FrameOrSeriesUnion: |
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.
@arw2019 just FYI
error: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables [misc]
when we add numpy types.
the problem is the Series in AnyArrayLike could be a Series subclass.
I would like to change AnyArrayLike to a Union instead of a TypeVar to avoid many issues like this
good news though. the ignore above is not needed.
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
xref https://github.com/pandas-dev/pandas/pull/38416/files#r549438292