-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ | |
from pandas._libs.lib import no_default | ||
from pandas._typing import ( | ||
AggFuncType, | ||
AnyArrayLike, | ||
ArrayLike, | ||
Axes, | ||
Axis, | ||
|
@@ -1141,7 +1142,17 @@ def __len__(self) -> int: | |
""" | ||
return len(self.index) | ||
|
||
def dot(self, other): | ||
# pandas/core/frame.py:1146: error: Overloaded function signatures 1 and 2 | ||
# overlap with incompatible return types [misc] | ||
@overload | ||
def dot(self, other: Series) -> Series: # type: ignore[misc] | ||
... | ||
|
||
@overload | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. @arw2019 just FYI
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. |
||
""" | ||
Compute the matrix multiplication between the DataFrame and other. | ||
|
||
|
@@ -1251,7 +1262,19 @@ def dot(self, other): | |
else: # pragma: no cover | ||
raise TypeError(f"unsupported type: {type(other)}") | ||
|
||
def __matmul__(self, other): | ||
@overload | ||
def __matmul__(self, other: Series) -> Series: | ||
... | ||
|
||
@overload | ||
def __matmul__( | ||
self, other: Union[AnyArrayLike, FrameOrSeriesUnion] | ||
) -> FrameOrSeriesUnion: | ||
... | ||
|
||
def __matmul__( | ||
self, other: Union[AnyArrayLike, FrameOrSeriesUnion] | ||
) -> FrameOrSeriesUnion: | ||
""" | ||
Matrix multiplication using binary `@` operator in Python>=3.5. | ||
""" | ||
|
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