Skip to content

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

Merged
merged 4 commits into from
Jan 5, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,14 @@ def __len__(self) -> int:
"""
return len(self.index)

@overload
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this ignore?

Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

def dot(self, other: Series) -> Series:
...

@overload
def dot(self, other: Union[DataFrame, Index, ArrayLike]) -> Optional[DataFrame]:
Copy link
Contributor

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?

Copy link
Member Author

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)

...

def dot(self, other):
"""
Compute the matrix multiplication between the DataFrame and other.
Expand Down Expand Up @@ -1267,6 +1275,16 @@ def dot(self, other):
else: # pragma: no cover
raise TypeError(f"unsupported type: {type(other)}")

@overload
def __matmul__(self, other: Series) -> Series:
...

@overload
def __matmul__(
self, other: Union[DataFrame, Index, ArrayLike]
) -> Optional[DataFrame]:
...

def __matmul__(self, other):
"""
Matrix multiplication using binary `@` operator in Python>=3.5.
Expand Down