Skip to content

Commit f9762cc

Browse files
authored
TYP: libs (#43430)
1 parent cce7d10 commit f9762cc

File tree

7 files changed

+63
-51
lines changed

7 files changed

+63
-51
lines changed

pandas/_libs/join.pyi

+19-17
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
11
import numpy as np
22

3+
from pandas._typing import npt
4+
35
def inner_join(
46
left: np.ndarray, # const intp_t[:]
57
right: np.ndarray, # const intp_t[:]
68
max_groups: int,
7-
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
9+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
810
def left_outer_join(
911
left: np.ndarray, # const intp_t[:]
1012
right: np.ndarray, # const intp_t[:]
1113
max_groups: int,
1214
sort: bool = True,
13-
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
15+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
1416
def full_outer_join(
1517
left: np.ndarray, # const intp_t[:]
1618
right: np.ndarray, # const intp_t[:]
1719
max_groups: int,
18-
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
20+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
1921
def ffill_indexer(
2022
indexer: np.ndarray, # const intp_t[:]
21-
) -> np.ndarray: ... # np.ndarray[np.intp]
23+
) -> npt.NDArray[np.intp]: ...
2224
def left_join_indexer_unique(
2325
left: np.ndarray, # ndarray[join_t]
2426
right: np.ndarray, # ndarray[join_t]
25-
) -> np.ndarray: ... # np.ndarray[np.intp]
27+
) -> npt.NDArray[np.intp]: ...
2628
def left_join_indexer(
2729
left: np.ndarray, # ndarray[join_t]
2830
right: np.ndarray, # ndarray[join_t]
2931
) -> tuple[
3032
np.ndarray, # np.ndarray[join_t]
31-
np.ndarray, # np.ndarray[np.intp]
32-
np.ndarray, # np.ndarray[np.intp]
33+
npt.NDArray[np.intp],
34+
npt.NDArray[np.intp],
3335
]: ...
3436
def inner_join_indexer(
3537
left: np.ndarray, # ndarray[join_t]
3638
right: np.ndarray, # ndarray[join_t]
3739
) -> tuple[
3840
np.ndarray, # np.ndarray[join_t]
39-
np.ndarray, # np.ndarray[np.intp]
40-
np.ndarray, # np.ndarray[np.intp]
41+
npt.NDArray[np.intp],
42+
npt.NDArray[np.intp],
4143
]: ...
4244
def outer_join_indexer(
4345
left: np.ndarray, # ndarray[join_t]
4446
right: np.ndarray, # ndarray[join_t]
4547
) -> tuple[
4648
np.ndarray, # np.ndarray[join_t]
47-
np.ndarray, # np.ndarray[np.intp]
48-
np.ndarray, # np.ndarray[np.intp]
49+
npt.NDArray[np.intp],
50+
npt.NDArray[np.intp],
4951
]: ...
5052
def asof_join_backward_on_X_by_Y(
5153
left_values: np.ndarray, # asof_t[:]
@@ -54,38 +56,38 @@ def asof_join_backward_on_X_by_Y(
5456
right_by_values: np.ndarray, # by_t[:]
5557
allow_exact_matches: bool = True,
5658
tolerance=None,
57-
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
59+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
5860
def asof_join_forward_on_X_by_Y(
5961
left_values: np.ndarray, # asof_t[:]
6062
right_values: np.ndarray, # asof_t[:]
6163
left_by_values: np.ndarray, # by_t[:]
6264
right_by_values: np.ndarray, # by_t[:]
6365
allow_exact_matches: bool = True,
6466
tolerance=None,
65-
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
67+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
6668
def asof_join_nearest_on_X_by_Y(
6769
left_values: np.ndarray, # asof_t[:]
6870
right_values: np.ndarray, # asof_t[:]
6971
left_by_values: np.ndarray, # by_t[:]
7072
right_by_values: np.ndarray, # by_t[:]
7173
allow_exact_matches: bool = True,
7274
tolerance=None,
73-
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
75+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
7476
def asof_join_backward(
7577
left_values: np.ndarray, # asof_t[:]
7678
right_values: np.ndarray, # asof_t[:]
7779
allow_exact_matches: bool = True,
7880
tolerance=None,
79-
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
81+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
8082
def asof_join_forward(
8183
left_values: np.ndarray, # asof_t[:]
8284
right_values: np.ndarray, # asof_t[:]
8385
allow_exact_matches: bool = True,
8486
tolerance=None,
85-
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
87+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...
8688
def asof_join_nearest(
8789
left_values: np.ndarray, # asof_t[:]
8890
right_values: np.ndarray, # asof_t[:]
8991
allow_exact_matches: bool = True,
9092
tolerance=None,
91-
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp]
93+
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp]]: ...

pandas/_libs/lib.pyi

+22-21
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import numpy as np
1414
from pandas._typing import (
1515
ArrayLike,
1616
DtypeObj,
17+
npt,
1718
)
1819

1920
# placeholder until we can specify np.ndarray[object, ndim=2]
@@ -63,7 +64,7 @@ def map_infer(
6364
) -> np.ndarray: ...
6465
@overload # both convert_datetime and convert_to_nullable_integer False -> np.ndarray
6566
def maybe_convert_objects(
66-
objects: np.ndarray, # np.ndarray[object]
67+
objects: npt.NDArray[np.object_],
6768
*,
6869
try_float: bool = ...,
6970
safe: bool = ...,
@@ -76,7 +77,7 @@ def maybe_convert_objects(
7677
) -> np.ndarray: ...
7778
@overload
7879
def maybe_convert_objects(
79-
objects: np.ndarray, # np.ndarray[object]
80+
objects: npt.NDArray[np.object_],
8081
*,
8182
try_float: bool = ...,
8283
safe: bool = ...,
@@ -89,7 +90,7 @@ def maybe_convert_objects(
8990
) -> ArrayLike: ...
9091
@overload
9192
def maybe_convert_objects(
92-
objects: np.ndarray, # np.ndarray[object]
93+
objects: npt.NDArray[np.object_],
9394
*,
9495
try_float: bool = ...,
9596
safe: bool = ...,
@@ -102,7 +103,7 @@ def maybe_convert_objects(
102103
) -> ArrayLike: ...
103104
@overload
104105
def maybe_convert_objects(
105-
objects: np.ndarray, # np.ndarray[object]
106+
objects: npt.NDArray[np.object_],
106107
*,
107108
try_float: bool = ...,
108109
safe: bool = ...,
@@ -115,7 +116,7 @@ def maybe_convert_objects(
115116
) -> ArrayLike: ...
116117
@overload
117118
def maybe_convert_objects(
118-
objects: np.ndarray, # np.ndarray[object]
119+
objects: npt.NDArray[np.object_],
119120
*,
120121
try_float: bool = ...,
121122
safe: bool = ...,
@@ -128,15 +129,15 @@ def maybe_convert_objects(
128129
) -> ArrayLike: ...
129130
@overload
130131
def maybe_convert_numeric(
131-
values: np.ndarray, # np.ndarray[object]
132+
values: npt.NDArray[np.object_],
132133
na_values: set,
133134
convert_empty: bool = True,
134135
coerce_numeric: bool = False,
135136
convert_to_masked_nullable: Literal[False] = ...,
136137
) -> tuple[np.ndarray, None]: ...
137138
@overload
138139
def maybe_convert_numeric(
139-
values: np.ndarray, # np.ndarray[object]
140+
values: npt.NDArray[np.object_],
140141
na_values: set,
141142
convert_empty: bool = True,
142143
coerce_numeric: bool = False,
@@ -151,32 +152,32 @@ def ensure_string_array(
151152
convert_na_value: bool = True,
152153
copy: bool = True,
153154
skipna: bool = True,
154-
) -> np.ndarray: ... # np.ndarray[object]
155+
) -> npt.NDArray[np.object_]: ...
155156
def infer_datetimelike_array(
156-
arr: np.ndarray, # np.ndarray[object]
157+
arr: npt.NDArray[np.object_],
157158
) -> tuple[str, bool]: ...
158159
def astype_intsafe(
159-
arr: np.ndarray, # np.ndarray[object]
160+
arr: npt.NDArray[np.object_],
160161
new_dtype: np.dtype,
161162
) -> np.ndarray: ...
162-
def fast_zip(ndarrays: list) -> np.ndarray: ... # np.ndarray[object]
163+
def fast_zip(ndarrays: list) -> npt.NDArray[np.object_]: ...
163164

164165
# TODO: can we be more specific about rows?
165166
def to_object_array_tuples(rows: object) -> ndarray_obj_2d: ...
166167
def tuples_to_object_array(
167-
tuples: np.ndarray, # np.ndarray[object]
168+
tuples: npt.NDArray[np.object_],
168169
) -> ndarray_obj_2d: ...
169170

170171
# TODO: can we be more specific about rows?
171172
def to_object_array(rows: object, min_width: int = 0) -> ndarray_obj_2d: ...
172173
def dicts_to_array(dicts: list, columns: list) -> ndarray_obj_2d: ...
173174
def maybe_booleans_to_slice(
174-
mask: np.ndarray, # ndarray[uint8_t]
175-
) -> slice | np.ndarray: ... # np.ndarray[np.uint8]
175+
mask: npt.NDArray[np.uint8],
176+
) -> slice | npt.NDArray[np.uint8]: ...
176177
def maybe_indices_to_slice(
177-
indices: np.ndarray, # np.ndarray[np.intp]
178+
indices: npt.NDArray[np.intp],
178179
max_len: int,
179-
) -> slice | np.ndarray: ... # np.ndarray[np.uint8]
180+
) -> slice | npt.NDArray[np.intp]: ...
180181
def is_all_arraylike(obj: list) -> bool: ...
181182

182183
# -----------------------------------------------------------------
@@ -192,14 +193,14 @@ def map_infer_mask(
192193
dtype: np.dtype = ...,
193194
) -> np.ndarray: ...
194195
def indices_fast(
195-
index: np.ndarray, # ndarray[intp_t]
196+
index: npt.NDArray[np.intp],
196197
labels: np.ndarray, # const int64_t[:]
197198
keys: list,
198-
sorted_labels: list[np.ndarray], # list[ndarray[np.int64]]
199+
sorted_labels: list[npt.NDArray[np.int64]],
199200
) -> dict: ...
200201
def generate_slices(
201202
labels: np.ndarray, ngroups: int # const intp_t[:]
202-
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.int64] # np.ndarray[np.int64]
203+
) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]: ...
203204
def count_level_2d(
204205
mask: np.ndarray, # ndarray[uint8_t, ndim=2, cast=True],
205206
labels: np.ndarray, # const intp_t[:]
@@ -211,7 +212,7 @@ def get_level_sorter(
211212
starts: np.ndarray, # const intp_t[:]
212213
) -> np.ndarray: ... # np.ndarray[np.intp, ndim=1]
213214
def generate_bins_dt64(
214-
values: np.ndarray, # np.ndarray[np.int64]
215+
values: npt.NDArray[np.int64],
215216
binner: np.ndarray, # const int64_t[:]
216217
closed: object = "left",
217218
hasnans: bool = False,
@@ -224,5 +225,5 @@ def has_infs(arr: np.ndarray) -> bool: ... # const floating[:]
224225
def get_reverse_indexer(
225226
indexer: np.ndarray, # const intp_t[:]
226227
length: int,
227-
) -> np.ndarray: ... # np.ndarray[np.intp]
228+
) -> npt.NDArray[np.intp]: ...
228229
def is_bool_list(obj: list) -> bool: ...

pandas/_libs/ops.pyi

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ from typing import (
77

88
import numpy as np
99

10+
from pandas._typing import npt
11+
1012
_BinOp = Callable[[Any, Any], Any]
1113
_BoolOp = Callable[[Any, Any], bool]
1214

1315
def scalar_compare(
1416
values: np.ndarray, # object[:]
1517
val: object,
1618
op: _BoolOp, # {operator.eq, operator.ne, ...}
17-
) -> np.ndarray: ... # np.ndarray[bool]
19+
) -> npt.NDArray[np.bool_]: ...
1820
def vec_compare(
19-
left: np.ndarray, # np.ndarray[object]
20-
right: np.ndarray, # np.ndarray[object]
21+
left: npt.NDArray[np.object_],
22+
right: npt.NDArray[np.object_],
2123
op: _BoolOp, # {operator.eq, operator.ne, ...}
22-
) -> np.ndarray: ... # np.ndarray[bool]
24+
) -> npt.NDArray[np.bool_]: ...
2325
def scalar_binop(
2426
values: np.ndarray, # object[:]
2527
val: object,
@@ -32,14 +34,14 @@ def vec_binop(
3234
) -> np.ndarray: ...
3335
@overload
3436
def maybe_convert_bool(
35-
arr: np.ndarray, # np.ndarray[object]
37+
arr: npt.NDArray[np.object_],
3638
true_values=...,
3739
false_values=...,
3840
convert_to_masked_nullable: Literal[False] = ...,
3941
) -> tuple[np.ndarray, None]: ...
4042
@overload
4143
def maybe_convert_bool(
42-
arr: np.ndarray, # np.ndarray[object]
44+
arr: npt.NDArray[np.object_],
4345
true_values=...,
4446
false_values=...,
4547
*,

pandas/_libs/parsers.pyi

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import numpy as np
88
from pandas._typing import (
99
ArrayLike,
1010
Dtype,
11+
npt,
1112
)
1213

1314
STR_NA_VALUES: set[str]
1415

1516
def sanitize_objects(
16-
values: np.ndarray, # ndarray[object]
17+
values: npt.NDArray[np.object_],
1718
na_values: set,
1819
convert_empty: bool = ...,
1920
) -> int: ...

pandas/_libs/reshape.pyi

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import numpy as np
22

3+
import pandas._tying as npt
4+
35
def unstack(
46
values: np.ndarray, # reshape_t[:, :]
57
mask: np.ndarray, # const uint8_t[:]
@@ -10,5 +12,5 @@ def unstack(
1012
new_mask: np.ndarray, # uint8_t[:, :]
1113
) -> None: ...
1214
def explode(
13-
values: np.ndarray, # np.ndarray[object]
14-
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[object] # np.ndarray[np.int64]
15+
values: npt.NDArray[np.object_],
16+
) -> tuple[npt.NDArray[np.object_], npt.NDArray[np.int64]]: ...

pandas/_libs/tslib.pyi

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ from datetime import tzinfo
22

33
import numpy as np
44

5+
from pandas._typing import npt
6+
57
def format_array_from_datetime(
6-
values: np.ndarray, # np.ndarray[np.int64]
8+
values: npt.NDArray[np.int64],
79
tz: tzinfo | None = ...,
810
format: str | None = ...,
911
na_rep: object = ...,
10-
) -> np.ndarray: ... # np.ndarray[object]
12+
) -> npt.NDArray[np.object_]: ...
1113
def array_with_unit_to_datetime(
1214
values: np.ndarray,
1315
unit: str,
1416
errors: str = ...,
1517
) -> tuple[np.ndarray, tzinfo | None]: ...
1618
def array_to_datetime(
17-
values: np.ndarray, # np.ndarray[object]
19+
values: npt.NDArray[np.object_],
1820
errors: str = ...,
1921
dayfirst: bool = ...,
2022
yearfirst: bool = ...,

pandas/_libs/window/indexers.pyi

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import numpy as np
22

3+
from pandas._typing import npt
4+
35
def calculate_variable_window_bounds(
46
num_values: int, # int64_t
57
window_size: int, # int64_t
68
min_periods,
79
center: bool,
810
closed: str | None,
911
index: np.ndarray, # const int64_t[:]
10-
) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.int64] # np.ndarray[np.int64]
12+
) -> tuple[npt.NDArray[np.int64], npt.NDArray[np.int64]]: ...

0 commit comments

Comments
 (0)