Skip to content

Commit 19e8c4b

Browse files
authored
Merge pull request numpy#28527 from jorenham/numtype/233
TYP: fix stubtest errors in ``numpy.lib._function_base_impl``
2 parents 52ae35f + a7b7b5b commit 19e8c4b

File tree

2 files changed

+95
-93
lines changed

2 files changed

+95
-93
lines changed

numpy/lib/_function_base_impl.pyi

Lines changed: 93 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,60 @@
1-
from collections.abc import Sequence, Callable, Iterable
1+
# ruff: noqa: ANN401
2+
from collections.abc import Callable, Iterable, Sequence
23
from typing import (
3-
Concatenate,
4-
Literal as L,
54
Any,
5+
Concatenate,
66
ParamSpec,
7-
TypeAlias,
8-
TypeVar,
9-
overload,
107
Protocol,
118
SupportsIndex,
129
SupportsInt,
13-
TypeGuard,
14-
type_check_only
10+
TypeAlias,
11+
TypeVar,
12+
overload,
13+
type_check_only,
1514
)
16-
from typing_extensions import deprecated
15+
from typing import Literal as L
16+
17+
from _typeshed import Incomplete
18+
from typing_extensions import TypeIs, deprecated
1719

1820
import numpy as np
1921
from numpy import (
20-
vectorize,
22+
_OrderKACF,
23+
bool_,
24+
complex128,
25+
complexfloating,
26+
datetime64,
27+
float64,
28+
floating,
2129
generic,
2230
integer,
23-
floating,
24-
complexfloating,
2531
intp,
26-
float64,
27-
complex128,
28-
timedelta64,
29-
datetime64,
3032
object_,
31-
bool_,
32-
_OrderKACF,
33+
timedelta64,
34+
vectorize,
3335
)
3436
from numpy._core.multiarray import bincount
37+
from numpy._globals import _NoValueType
3538
from numpy._typing import (
36-
NDArray,
3739
ArrayLike,
3840
DTypeLike,
41+
NDArray,
3942
_ArrayLike,
40-
_DTypeLike,
41-
_ShapeLike,
4243
_ArrayLikeBool_co,
43-
_ArrayLikeInt_co,
44-
_ArrayLikeFloat_co,
4544
_ArrayLikeComplex_co,
46-
_ArrayLikeNumber_co,
47-
_ArrayLikeTD64_co,
4845
_ArrayLikeDT64_co,
46+
_ArrayLikeFloat_co,
47+
_ArrayLikeInt_co,
48+
_ArrayLikeNumber_co,
4949
_ArrayLikeObject_co,
50-
_FloatLike_co,
50+
_ArrayLikeTD64_co,
5151
_ComplexLike_co,
52+
_DTypeLike,
53+
_FloatLike_co,
54+
_NestedSequence,
5255
_NumberLike_co,
5356
_ScalarLike_co,
54-
_NestedSequence
57+
_ShapeLike,
5558
)
5659

5760
__all__ = [
@@ -109,12 +112,14 @@ _MeshgridIdx: TypeAlias = L['ij', 'xy']
109112

110113
@type_check_only
111114
class _TrimZerosSequence(Protocol[_T_co]):
112-
def __len__(self) -> int: ...
115+
def __len__(self, /) -> int: ...
113116
@overload
114117
def __getitem__(self, key: int, /) -> object: ...
115118
@overload
116119
def __getitem__(self, key: slice, /) -> _T_co: ...
117120

121+
###
122+
118123
@overload
119124
def rot90(
120125
m: _ArrayLike[_SCT],
@@ -137,72 +142,62 @@ def flip(m: _ArrayLike[_SCT], axis: None | _ShapeLike = ...) -> NDArray[_SCT]: .
137142
@overload
138143
def flip(m: ArrayLike, axis: None | _ShapeLike = ...) -> NDArray[Any]: ...
139144

140-
def iterable(y: object) -> TypeGuard[Iterable[Any]]: ...
145+
def iterable(y: object) -> TypeIs[Iterable[Any]]: ...
141146

142147
@overload
143148
def average(
144149
a: _ArrayLikeFloat_co,
145-
axis: None = ...,
146-
weights: None | _ArrayLikeFloat_co = ...,
147-
returned: L[False] = ...,
148-
keepdims: L[False] = ...,
149-
) -> floating[Any]: ...
150-
@overload
151-
def average(
152-
a: _ArrayLikeComplex_co,
153-
axis: None = ...,
154-
weights: None | _ArrayLikeComplex_co = ...,
155-
returned: L[False] = ...,
156-
keepdims: L[False] = ...,
157-
) -> complexfloating[Any, Any]: ...
158-
@overload
159-
def average(
160-
a: _ArrayLikeObject_co,
161-
axis: None = ...,
162-
weights: None | Any = ...,
163-
returned: L[False] = ...,
164-
keepdims: L[False] = ...,
165-
) -> Any: ...
150+
axis: None = None,
151+
weights: _ArrayLikeFloat_co | None = None,
152+
returned: L[False] = False,
153+
*,
154+
keepdims: L[False] | _NoValueType = ...,
155+
) -> floating: ...
166156
@overload
167157
def average(
168158
a: _ArrayLikeFloat_co,
169-
axis: None = ...,
170-
weights: None | _ArrayLikeFloat_co = ...,
171-
returned: L[True] = ...,
172-
keepdims: L[False] = ...,
173-
) -> _2Tuple[floating[Any]]: ...
159+
axis: None = None,
160+
weights: _ArrayLikeFloat_co | None = None,
161+
*,
162+
returned: L[True],
163+
keepdims: L[False] | _NoValueType = ...,
164+
) -> _2Tuple[floating]: ...
174165
@overload
175166
def average(
176167
a: _ArrayLikeComplex_co,
177-
axis: None = ...,
178-
weights: None | _ArrayLikeComplex_co = ...,
179-
returned: L[True] = ...,
180-
keepdims: L[False] = ...,
181-
) -> _2Tuple[complexfloating[Any, Any]]: ...
168+
axis: None = None,
169+
weights: _ArrayLikeComplex_co | None = None,
170+
returned: L[False] = False,
171+
*,
172+
keepdims: L[False] | _NoValueType = ...,
173+
) -> complexfloating: ...
182174
@overload
183175
def average(
184-
a: _ArrayLikeObject_co,
185-
axis: None = ...,
186-
weights: None | Any = ...,
187-
returned: L[True] = ...,
188-
keepdims: L[False] = ...,
189-
) -> _2Tuple[Any]: ...
176+
a: _ArrayLikeComplex_co,
177+
axis: None = None,
178+
weights: _ArrayLikeComplex_co | None = None,
179+
*,
180+
returned: L[True],
181+
keepdims: L[False] | _NoValueType = ...,
182+
) -> _2Tuple[complexfloating]: ...
190183
@overload
191184
def average(
192185
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
193-
axis: None | _ShapeLike = ...,
194-
weights: None | Any = ...,
195-
returned: L[False] = ...,
196-
keepdims: bool = ...,
197-
) -> Any: ...
186+
axis: _ShapeLike | None = None,
187+
weights: object | None = None,
188+
*,
189+
returned: L[True],
190+
keepdims: bool | bool_ | _NoValueType = ...,
191+
) -> _2Tuple[Incomplete]: ...
198192
@overload
199193
def average(
200194
a: _ArrayLikeComplex_co | _ArrayLikeObject_co,
201-
axis: None | _ShapeLike = ...,
202-
weights: None | Any = ...,
203-
returned: L[True] = ...,
204-
keepdims: bool = ...,
205-
) -> _2Tuple[Any]: ...
195+
axis: _ShapeLike | None = None,
196+
weights: object | None = None,
197+
returned: bool | bool_ = False,
198+
*,
199+
keepdims: bool | bool_ | _NoValueType = ...,
200+
) -> Incomplete: ...
206201

207202
@overload
208203
def asarray_chkfinite(
@@ -481,38 +476,46 @@ def cov(
481476
dtype: DTypeLike,
482477
) -> NDArray[Any]: ...
483478

484-
# NOTE `bias` and `ddof` have been deprecated
479+
# NOTE `bias` and `ddof` are deprecated and ignored
485480
@overload
486481
def corrcoef(
487482
m: _ArrayLikeFloat_co,
488-
y: None | _ArrayLikeFloat_co = ...,
489-
rowvar: bool = ...,
483+
y: _ArrayLikeFloat_co | None = None,
484+
rowvar: bool = True,
485+
bias: _NoValueType = ...,
486+
ddof: _NoValueType = ...,
490487
*,
491-
dtype: None = ...,
492-
) -> NDArray[floating[Any]]: ...
488+
dtype: None = None,
489+
) -> NDArray[floating]: ...
493490
@overload
494491
def corrcoef(
495492
m: _ArrayLikeComplex_co,
496-
y: None | _ArrayLikeComplex_co = ...,
497-
rowvar: bool = ...,
493+
y: _ArrayLikeComplex_co | None = None,
494+
rowvar: bool = True,
495+
bias: _NoValueType = ...,
496+
ddof: _NoValueType = ...,
498497
*,
499-
dtype: None = ...,
500-
) -> NDArray[complexfloating[Any, Any]]: ...
498+
dtype: None = None,
499+
) -> NDArray[complexfloating]: ...
501500
@overload
502501
def corrcoef(
503502
m: _ArrayLikeComplex_co,
504-
y: None | _ArrayLikeComplex_co = ...,
505-
rowvar: bool = ...,
503+
y: _ArrayLikeComplex_co | None = None,
504+
rowvar: bool = True,
505+
bias: _NoValueType = ...,
506+
ddof: _NoValueType = ...,
506507
*,
507508
dtype: _DTypeLike[_SCT],
508509
) -> NDArray[_SCT]: ...
509510
@overload
510511
def corrcoef(
511512
m: _ArrayLikeComplex_co,
512-
y: None | _ArrayLikeComplex_co = ...,
513-
rowvar: bool = ...,
513+
y: _ArrayLikeComplex_co | None = None,
514+
rowvar: bool = True,
515+
bias: _NoValueType = ...,
516+
ddof: _NoValueType = ...,
514517
*,
515-
dtype: DTypeLike,
518+
dtype: DTypeLike | None = None,
516519
) -> NDArray[Any]: ...
517520

518521
def blackman(M: _FloatLike_co) -> NDArray[floating[Any]]: ...
@@ -584,7 +587,6 @@ def median(
584587
a: _ArrayLikeFloat_co | _ArrayLikeComplex_co | _ArrayLikeTD64_co | _ArrayLikeObject_co,
585588
axis: None | _ShapeLike,
586589
out: _ArrayType,
587-
/,
588590
overwrite_input: bool = ...,
589591
keepdims: bool = ...,
590592
) -> _ArrayType: ...
@@ -752,7 +754,6 @@ def percentile(
752754
q: _ArrayLikeFloat_co,
753755
axis: None | _ShapeLike,
754756
out: _ArrayType,
755-
/,
756757
overwrite_input: bool = ...,
757758
method: _MethodKind = ...,
758759
keepdims: bool = ...,

numpy/ma/extras.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from typing import Any
22

3+
from numpy.lib._function_base_impl import average
34
from numpy.lib._index_tricks_impl import AxisConcatenator
5+
46
from .core import dot, mask_rowcols
57

68
__all__ = [
@@ -88,7 +90,6 @@ diagflat: _fromnxfunction_single
8890

8991
def apply_along_axis(func1d, axis, arr, *args, **kwargs): ...
9092
def apply_over_axes(func, a, axes): ...
91-
def average(a, axis=..., weights=..., returned=..., keepdims=...): ...
9293
def median(a, axis=..., out=..., overwrite_input=..., keepdims=...): ...
9394
def compress_nd(x, axis=...): ...
9495
def compress_rowcols(x, axis=...): ...

0 commit comments

Comments
 (0)