From b42cfbcc7eb6665bd977cd55d3816ee8666911ba Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 15 Mar 2021 18:00:00 -0700 Subject: [PATCH 1/5] TYP: ops.pyi, hashing.pyi --- pandas/_libs/hashing.pyi | 7 +++++++ pandas/_libs/ops.pyi | 43 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 pandas/_libs/hashing.pyi create mode 100644 pandas/_libs/ops.pyi diff --git a/pandas/_libs/hashing.pyi b/pandas/_libs/hashing.pyi new file mode 100644 index 0000000000000..af15abe24f08e --- /dev/null +++ b/pandas/_libs/hashing.pyi @@ -0,0 +1,7 @@ +import numpy as np + +def hash_object_array( + arr: np.ndarray, # np.ndarray[object] + key: str, + encoding: str = "utf8", +) -> np.ndarray: ... # np.ndarray[np.uint64] diff --git a/pandas/_libs/ops.pyi b/pandas/_libs/ops.pyi new file mode 100644 index 0000000000000..37dc63d91363c --- /dev/null +++ b/pandas/_libs/ops.pyi @@ -0,0 +1,43 @@ +from typing import ( + Any, + Callable, +) + +import numpy as np + +binop = Callable[[Any, Any], Any] +bool_op = Callable[[Any, Any], bool] + + +def scalar_compare( + values: np.ndarray, # object[:] + val: object, + op: bool_op, # {operator.eq, operator.ne, ...} +) -> np.ndarray: ... # np.ndarray[bool] + +def vec_compare( + left: np.ndarray, # np.ndarray[object] + right: np.ndarray, # np.ndarray[object] + op: bool_op, # {operator.eq, operator.ne, ...} +) -> np.ndarray: ... # np.ndarray[bool] + + +def scalar_binop( + values: np.ndarray, # object[:] + val: object, + op: binop, # binary operator +) -> np.ndarray: ... + + +def vec_binop( + left: np.ndarray, # object[:] + right: np.ndarray, # object[:] + op: binop, # binary operator +) -> np.ndarray: ... + + +def maybe_convert_bool( + arr: np.ndarray, # np.ndarray[object] + true_values=None, + false_values=None +) -> np.ndarray: ... From 28cf04ab144092d0b2edd6854d33488ee0fa69d6 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 15 Mar 2021 18:02:13 -0700 Subject: [PATCH 2/5] TYP: ops_dispatch.pyi --- pandas/_libs/ops_dispatch.pyi | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 pandas/_libs/ops_dispatch.pyi diff --git a/pandas/_libs/ops_dispatch.pyi b/pandas/_libs/ops_dispatch.pyi new file mode 100644 index 0000000000000..891fb7a1ffff2 --- /dev/null +++ b/pandas/_libs/ops_dispatch.pyi @@ -0,0 +1,9 @@ +import numpy as np + +REVERSED_NAMES: dict[str, str] +UFUNC_ALIASES: dict[str, str] +DISPATCHED_UFUNCS: set[str] + +def maybe_dispatch_ufunc_to_dunder_op( + self, ufunc: np.ufunc, method: str, *inputs, **kwargs +): ... From cc974bbe5bc2290766267bb56e9a38c0a73ec66d Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 15 Mar 2021 18:03:29 -0700 Subject: [PATCH 3/5] TYP: reshape.pyi --- pandas/_libs/reshape.pyi | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 pandas/_libs/reshape.pyi diff --git a/pandas/_libs/reshape.pyi b/pandas/_libs/reshape.pyi new file mode 100644 index 0000000000000..7aaa18a7feff2 --- /dev/null +++ b/pandas/_libs/reshape.pyi @@ -0,0 +1,19 @@ +import numpy as np + +def unstack( + values: np.ndarray, # reshape_t[:, :] + mask: np.ndarray, # const uint8_t[:] + stride: int, + length: int, + width: int, + new_values: np.ndarray, # reshape_t[:, :] + new_mask: np.ndarray, # uint8_t[:, :] +) -> None: ... + + +def explode( + values: np.ndarray, # np.ndarray[object] +) -> tuple[ + np.ndarray, # np.ndarray[object] + np.ndarray, # np.ndarray[np.int64] +]: ... From a2ab5ab251c7da4246ed54742cc17285b1f781ef Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 16 Mar 2021 08:11:00 -0700 Subject: [PATCH 4/5] update per suggestions --- pandas/_libs/ops.pyi | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/_libs/ops.pyi b/pandas/_libs/ops.pyi index 37dc63d91363c..b4f42f217a5db 100644 --- a/pandas/_libs/ops.pyi +++ b/pandas/_libs/ops.pyi @@ -5,39 +5,39 @@ from typing import ( import numpy as np -binop = Callable[[Any, Any], Any] -bool_op = Callable[[Any, Any], bool] +_BinOp = Callable[[Any, Any], Any] +_BoolOp = Callable[[Any, Any], bool] def scalar_compare( values: np.ndarray, # object[:] val: object, - op: bool_op, # {operator.eq, operator.ne, ...} + op: _BoolOp, # {operator.eq, operator.ne, ...} ) -> np.ndarray: ... # np.ndarray[bool] def vec_compare( left: np.ndarray, # np.ndarray[object] right: np.ndarray, # np.ndarray[object] - op: bool_op, # {operator.eq, operator.ne, ...} + op: _BoolOp, # {operator.eq, operator.ne, ...} ) -> np.ndarray: ... # np.ndarray[bool] def scalar_binop( values: np.ndarray, # object[:] val: object, - op: binop, # binary operator + op: _BinOp, # binary operator ) -> np.ndarray: ... def vec_binop( left: np.ndarray, # object[:] right: np.ndarray, # object[:] - op: binop, # binary operator + op: _BinOp, # binary operator ) -> np.ndarray: ... def maybe_convert_bool( arr: np.ndarray, # np.ndarray[object] - true_values=None, - false_values=None + true_values=..., + false_values=... ) -> np.ndarray: ... From 6db2ea315716dea120b259cd8e1856f93d139c00 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 16 Mar 2021 12:02:13 -0700 Subject: [PATCH 5/5] remove extraneous info --- pandas/_libs/hashing.pyi | 2 +- pandas/_libs/ops_dispatch.pyi | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/pandas/_libs/hashing.pyi b/pandas/_libs/hashing.pyi index af15abe24f08e..2844ec9b06557 100644 --- a/pandas/_libs/hashing.pyi +++ b/pandas/_libs/hashing.pyi @@ -3,5 +3,5 @@ import numpy as np def hash_object_array( arr: np.ndarray, # np.ndarray[object] key: str, - encoding: str = "utf8", + encoding: str = ..., ) -> np.ndarray: ... # np.ndarray[np.uint64] diff --git a/pandas/_libs/ops_dispatch.pyi b/pandas/_libs/ops_dispatch.pyi index 891fb7a1ffff2..91b5a4dbaaebc 100644 --- a/pandas/_libs/ops_dispatch.pyi +++ b/pandas/_libs/ops_dispatch.pyi @@ -1,9 +1,5 @@ import numpy as np -REVERSED_NAMES: dict[str, str] -UFUNC_ALIASES: dict[str, str] -DISPATCHED_UFUNCS: set[str] - def maybe_dispatch_ufunc_to_dunder_op( self, ufunc: np.ufunc, method: str, *inputs, **kwargs ): ...