From c33573881927a9611b15467e4865adbffa72987b Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Mon, 28 Dec 2020 18:30:05 -0500 Subject: [PATCH 1/3] type DataFrame.(dot, __matmul__) --- pandas/core/frame.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 9097ac13192c9..37e45b0e12df8 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1157,6 +1157,14 @@ def __len__(self) -> int: """ return len(self.index) + @overload + def dot(self, other: Series) -> Series: + ... + + @overload + def dot(self, other: Union[DataFrame, Index, ArrayLike]) -> Optional[DataFrame]: + ... + def dot(self, other): """ Compute the matrix multiplication between the DataFrame and other. @@ -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. From 4c95619349defa5925225972205fe0eecf6978e3 Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Sun, 3 Jan 2021 21:33:11 -0500 Subject: [PATCH 2/3] fix type hints --- pandas/core/frame.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index c6c06b00d7952..99ee7deb242c5 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -48,6 +48,7 @@ from pandas._libs.lib import no_default from pandas._typing import ( AggFuncType, + AnyArrayLike, ArrayLike, Axes, Axis, @@ -1142,14 +1143,14 @@ def __len__(self) -> int: return len(self.index) @overload - def dot(self, other: Series) -> Series: + def dot(self, other: Series) -> Series: # type: ignore[misc] ... @overload - def dot(self, other: Union[DataFrame, Index, ArrayLike]) -> Optional[DataFrame]: + def dot(self, other: Union[DataFrame, Index, ArrayLike]) -> DataFrame: ... - def dot(self, other): + def dot(self, other: Union[AnyArrayLike, FrameOrSeriesUnion]) -> FrameOrSeriesUnion: """ Compute the matrix multiplication between the DataFrame and other. @@ -1265,11 +1266,13 @@ def __matmul__(self, other: Series) -> Series: @overload def __matmul__( - self, other: Union[DataFrame, Index, ArrayLike] - ) -> Optional[DataFrame]: + self, other: Union[AnyArrayLike, FrameOrSeriesUnion] + ) -> FrameOrSeriesUnion: ... - def __matmul__(self, other): + def __matmul__( + self, other: Union[AnyArrayLike, FrameOrSeriesUnion] + ) -> FrameOrSeriesUnion: """ Matrix multiplication using binary `@` operator in Python>=3.5. """ From 7668016bbcfc0a8e70aefa59142a29ae1836b4f6 Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Mon, 4 Jan 2021 17:21:23 -0500 Subject: [PATCH 3/3] address review --- pandas/core/frame.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 99ee7deb242c5..1abbe37e67b09 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1142,6 +1142,8 @@ def __len__(self) -> int: """ return len(self.index) + # 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] ...