Skip to content

TYP: libs #43430

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 1 commit into from
Sep 9, 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
36 changes: 19 additions & 17 deletions pandas/_libs/join.pyi
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
import numpy as np

from pandas._typing import npt

def inner_join(
left: np.ndarray, # const intp_t[:]
right: np.ndarray, # const intp_t[:]
max_groups: int,
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
def left_outer_join(
left: np.ndarray, # const intp_t[:]
right: np.ndarray, # const intp_t[:]
max_groups: int,
sort: bool = True,
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
def full_outer_join(
left: np.ndarray, # const intp_t[:]
right: np.ndarray, # const intp_t[:]
max_groups: int,
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
def ffill_indexer(
indexer: np.ndarray, # const intp_t[:]
) -> np.ndarray: ... # np.ndarray[np.intp]
) -> npt.NDArray[np.intp]: ...
def left_join_indexer_unique(
left: np.ndarray, # ndarray[join_t]
right: np.ndarray, # ndarray[join_t]
) -> np.ndarray: ... # np.ndarray[np.intp]
) -> npt.NDArray[np.intp]: ...
def left_join_indexer(
left: np.ndarray, # ndarray[join_t]
right: np.ndarray, # ndarray[join_t]
) -> tuple[
np.ndarray, # np.ndarray[join_t]
np.ndarray, # np.ndarray[np.intp]
np.ndarray, # np.ndarray[np.intp]
npt.NDArray[np.intp],
npt.NDArray[np.intp],
]: ...
def inner_join_indexer(
left: np.ndarray, # ndarray[join_t]
right: np.ndarray, # ndarray[join_t]
) -> tuple[
np.ndarray, # np.ndarray[join_t]
np.ndarray, # np.ndarray[np.intp]
np.ndarray, # np.ndarray[np.intp]
npt.NDArray[np.intp],
npt.NDArray[np.intp],
]: ...
def outer_join_indexer(
left: np.ndarray, # ndarray[join_t]
right: np.ndarray, # ndarray[join_t]
) -> tuple[
np.ndarray, # np.ndarray[join_t]
np.ndarray, # np.ndarray[np.intp]
np.ndarray, # np.ndarray[np.intp]
npt.NDArray[np.intp],
npt.NDArray[np.intp],
]: ...
def asof_join_backward_on_X_by_Y(
left_values: np.ndarray, # asof_t[:]
Expand All @@ -54,38 +56,38 @@ def asof_join_backward_on_X_by_Y(
right_by_values: np.ndarray, # by_t[:]
allow_exact_matches: bool = True,
tolerance=None,
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
def asof_join_forward_on_X_by_Y(
left_values: np.ndarray, # asof_t[:]
right_values: np.ndarray, # asof_t[:]
left_by_values: np.ndarray, # by_t[:]
right_by_values: np.ndarray, # by_t[:]
allow_exact_matches: bool = True,
tolerance=None,
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
def asof_join_nearest_on_X_by_Y(
left_values: np.ndarray, # asof_t[:]
right_values: np.ndarray, # asof_t[:]
left_by_values: np.ndarray, # by_t[:]
right_by_values: np.ndarray, # by_t[:]
allow_exact_matches: bool = True,
tolerance=None,
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
def asof_join_backward(
left_values: np.ndarray, # asof_t[:]
right_values: np.ndarray, # asof_t[:]
allow_exact_matches: bool = True,
tolerance=None,
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
def asof_join_forward(
left_values: np.ndarray, # asof_t[:]
right_values: np.ndarray, # asof_t[:]
allow_exact_matches: bool = True,
tolerance=None,
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
def asof_join_nearest(
left_values: np.ndarray, # asof_t[:]
right_values: np.ndarray, # asof_t[:]
allow_exact_matches: bool = True,
tolerance=None,
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
43 changes: 22 additions & 21 deletions pandas/_libs/lib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import numpy as np
from pandas._typing import (
ArrayLike,
DtypeObj,
npt,
)

# placeholder until we can specify np.ndarray[object, ndim=2]
Expand Down Expand Up @@ -63,7 +64,7 @@ def map_infer(
) -> np.ndarray: ...
@overload # both convert_datetime and convert_to_nullable_integer False -> np.ndarray
def maybe_convert_objects(
objects: np.ndarray, # np.ndarray[object]
objects: npt.NDArray[np.object_],
*,
try_float: bool = ...,
safe: bool = ...,
Expand All @@ -76,7 +77,7 @@ def maybe_convert_objects(
) -> np.ndarray: ...
@overload
def maybe_convert_objects(
objects: np.ndarray, # np.ndarray[object]
objects: npt.NDArray[np.object_],
*,
try_float: bool = ...,
safe: bool = ...,
Expand All @@ -89,7 +90,7 @@ def maybe_convert_objects(
) -> ArrayLike: ...
@overload
def maybe_convert_objects(
objects: np.ndarray, # np.ndarray[object]
objects: npt.NDArray[np.object_],
*,
try_float: bool = ...,
safe: bool = ...,
Expand All @@ -102,7 +103,7 @@ def maybe_convert_objects(
) -> ArrayLike: ...
@overload
def maybe_convert_objects(
objects: np.ndarray, # np.ndarray[object]
objects: npt.NDArray[np.object_],
*,
try_float: bool = ...,
safe: bool = ...,
Expand All @@ -115,7 +116,7 @@ def maybe_convert_objects(
) -> ArrayLike: ...
@overload
def maybe_convert_objects(
objects: np.ndarray, # np.ndarray[object]
objects: npt.NDArray[np.object_],
*,
try_float: bool = ...,
safe: bool = ...,
Expand All @@ -128,15 +129,15 @@ def maybe_convert_objects(
) -> ArrayLike: ...
@overload
def maybe_convert_numeric(
values: np.ndarray, # np.ndarray[object]
values: npt.NDArray[np.object_],
na_values: set,
convert_empty: bool = True,
coerce_numeric: bool = False,
convert_to_masked_nullable: Literal[False] = ...,
) -> tuple[np.ndarray, None]: ...
@overload
def maybe_convert_numeric(
values: np.ndarray, # np.ndarray[object]
values: npt.NDArray[np.object_],
na_values: set,
convert_empty: bool = True,
coerce_numeric: bool = False,
Expand All @@ -151,32 +152,32 @@ def ensure_string_array(
convert_na_value: bool = True,
copy: bool = True,
skipna: bool = True,
) -> np.ndarray: ... # np.ndarray[object]
) -> npt.NDArray[np.object_]: ...
def infer_datetimelike_array(
arr: np.ndarray, # np.ndarray[object]
arr: npt.NDArray[np.object_],
) -> tuple[str, bool]: ...
def astype_intsafe(
arr: np.ndarray, # np.ndarray[object]
arr: npt.NDArray[np.object_],
new_dtype: np.dtype,
) -> np.ndarray: ...
def fast_zip(ndarrays: list) -> np.ndarray: ... # np.ndarray[object]
def fast_zip(ndarrays: list) -> npt.NDArray[np.object_]: ...

# TODO: can we be more specific about rows?
def to_object_array_tuples(rows: object) -> ndarray_obj_2d: ...
def tuples_to_object_array(
tuples: np.ndarray, # np.ndarray[object]
tuples: npt.NDArray[np.object_],
) -> ndarray_obj_2d: ...

# TODO: can we be more specific about rows?
def to_object_array(rows: object, min_width: int = 0) -> ndarray_obj_2d: ...
def dicts_to_array(dicts: list, columns: list) -> ndarray_obj_2d: ...
def maybe_booleans_to_slice(
mask: np.ndarray, # ndarray[uint8_t]
) -> slice | np.ndarray: ... # np.ndarray[np.uint8]
mask: npt.NDArray[np.uint8],
) -> slice | npt.NDArray[np.uint8]: ...
def maybe_indices_to_slice(
indices: np.ndarray, # np.ndarray[np.intp]
indices: npt.NDArray[np.intp],
max_len: int,
) -> slice | np.ndarray: ... # np.ndarray[np.uint8]
) -> slice | npt.NDArray[np.intp]: ...
def is_all_arraylike(obj: list) -> bool: ...

# -----------------------------------------------------------------
Expand All @@ -192,14 +193,14 @@ def map_infer_mask(
dtype: np.dtype = ...,
) -> np.ndarray: ...
def indices_fast(
index: np.ndarray, # ndarray[intp_t]
index: npt.NDArray[np.intp],
labels: np.ndarray, # const int64_t[:]
keys: list,
sorted_labels: list[np.ndarray], # list[ndarray[np.int64]]
sorted_labels: list[npt.NDArray[np.int64]],
) -> dict: ...
def generate_slices(
labels: np.ndarray, ngroups: int # const intp_t[:]
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.int64] # np.ndarray[np.int64]
) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]: ...
def count_level_2d(
mask: np.ndarray, # ndarray[uint8_t, ndim=2, cast=True],
labels: np.ndarray, # const intp_t[:]
Expand All @@ -211,7 +212,7 @@ def get_level_sorter(
starts: np.ndarray, # const intp_t[:]
) -> np.ndarray: ... # np.ndarray[np.intp, ndim=1]
def generate_bins_dt64(
values: np.ndarray, # np.ndarray[np.int64]
values: npt.NDArray[np.int64],
binner: np.ndarray, # const int64_t[:]
closed: object = "left",
hasnans: bool = False,
Expand All @@ -224,5 +225,5 @@ def has_infs(arr: np.ndarray) -> bool: ... # const floating[:]
def get_reverse_indexer(
indexer: np.ndarray, # const intp_t[:]
length: int,
) -> np.ndarray: ... # np.ndarray[np.intp]
) -> npt.NDArray[np.intp]: ...
def is_bool_list(obj: list) -> bool: ...
14 changes: 8 additions & 6 deletions pandas/_libs/ops.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ from typing import (

import numpy as np

from pandas._typing import npt

_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]
) -> npt.NDArray[np.bool_]: ...
def vec_compare(
left: np.ndarray, # np.ndarray[object]
right: np.ndarray, # np.ndarray[object]
left: npt.NDArray[np.object_],
right: npt.NDArray[np.object_],
op: _BoolOp, # {operator.eq, operator.ne, ...}
) -> np.ndarray: ... # np.ndarray[bool]
) -> npt.NDArray[np.bool_]: ...
def scalar_binop(
values: np.ndarray, # object[:]
val: object,
Expand All @@ -32,14 +34,14 @@ def vec_binop(
) -> np.ndarray: ...
@overload
def maybe_convert_bool(
arr: np.ndarray, # np.ndarray[object]
arr: npt.NDArray[np.object_],
true_values=...,
false_values=...,
convert_to_masked_nullable: Literal[False] = ...,
) -> tuple[np.ndarray, None]: ...
@overload
def maybe_convert_bool(
arr: np.ndarray, # np.ndarray[object]
arr: npt.NDArray[np.object_],
true_values=...,
false_values=...,
*,
Expand Down
3 changes: 2 additions & 1 deletion pandas/_libs/parsers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import numpy as np
from pandas._typing import (
ArrayLike,
Dtype,
npt,
)

STR_NA_VALUES: set[str]

def sanitize_objects(
values: np.ndarray, # ndarray[object]
values: npt.NDArray[np.object_],
na_values: set,
convert_empty: bool = ...,
) -> int: ...
Expand Down
6 changes: 4 additions & 2 deletions pandas/_libs/reshape.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import numpy as np

import pandas._tying as npt

def unstack(
values: np.ndarray, # reshape_t[:, :]
mask: np.ndarray, # const uint8_t[:]
Expand All @@ -10,5 +12,5 @@ def unstack(
new_mask: np.ndarray, # uint8_t[:, :]
) -> None: ...
def explode(
values: np.ndarray, # np.ndarray[object]
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[object] # np.ndarray[np.int64]
values: npt.NDArray[np.object_],
) -> tuple[npt.NDArray[np.object_], npt.NDArray[np.int64]]: ...
8 changes: 5 additions & 3 deletions pandas/_libs/tslib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ from datetime import tzinfo

import numpy as np

from pandas._typing import npt

def format_array_from_datetime(
values: np.ndarray, # np.ndarray[np.int64]
values: npt.NDArray[np.int64],
tz: tzinfo | None = ...,
format: str | None = ...,
na_rep: object = ...,
) -> np.ndarray: ... # np.ndarray[object]
) -> npt.NDArray[np.object_]: ...
def array_with_unit_to_datetime(
values: np.ndarray,
unit: str,
errors: str = ...,
) -> tuple[np.ndarray, tzinfo | None]: ...
def array_to_datetime(
values: np.ndarray, # np.ndarray[object]
values: npt.NDArray[np.object_],
errors: str = ...,
dayfirst: bool = ...,
yearfirst: bool = ...,
Expand Down
4 changes: 3 additions & 1 deletion pandas/_libs/window/indexers.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import numpy as np

from pandas._typing import npt

def calculate_variable_window_bounds(
num_values: int, # int64_t
window_size: int, # int64_t
min_periods,
center: bool,
closed: str | None,
index: np.ndarray, # const int64_t[:]
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.int64] # np.ndarray[np.int64]
) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]: ...