Skip to content

TYP: stubs for reshape, ops, ops_dispatch, hashing #40455

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 8 commits into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions pandas/_libs/hashing.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import numpy as np

def hash_object_array(
arr: np.ndarray, # np.ndarray[object]
key: str,
encoding: str = ...,
) -> np.ndarray: ... # np.ndarray[np.uint64]
43 changes: 43 additions & 0 deletions pandas/_libs/ops.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from typing import (
Any,
Callable,
)

import numpy as np

_BinOp = Callable[[Any, Any], Any]
_BoolOp = Callable[[Any, Any], bool]


def scalar_compare(
values: np.ndarray, # object[:]
val: object,
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: _BoolOp, # {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=...,
false_values=...
) -> np.ndarray: ...
5 changes: 5 additions & 0 deletions pandas/_libs/ops_dispatch.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import numpy as np

def maybe_dispatch_ufunc_to_dunder_op(
self, ufunc: np.ufunc, method: str, *inputs, **kwargs
Copy link
Member

Choose a reason for hiding this comment

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

maybe type self, since function is not a method

Copy link
Member Author

Choose a reason for hiding this comment

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

will take some tracking down, since it is called via arraylike.array_ufunc, which doesnt type self

): ...
19 changes: 19 additions & 0 deletions pandas/_libs/reshape.pyi
Original file line number Diff line number Diff line change
@@ -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]
]: ...