diff --git a/src/numpy-stubs/@test/static/accept/lib_function_base.pyi b/src/numpy-stubs/@test/static/accept/lib_function_base.pyi index 07422bec..81b02da7 100644 --- a/src/numpy-stubs/@test/static/accept/lib_function_base.pyi +++ b/src/numpy-stubs/@test/static/accept/lib_function_base.pyi @@ -145,33 +145,45 @@ assert_type(np.median(AR_f8, keepdims=True), Any) assert_type(np.median(AR_c16, axis=0), Any) assert_type(np.median(AR_LIKE_f, out=AR_c16), _nt.Array[np.complex128]) -assert_type(np.percentile(AR_f8, 50), np.floating) -assert_type(np.percentile(AR_c16, 50), np.complexfloating) +# percentile +assert_type(np.percentile(AR_f8, 50), np.float64) +assert_type(np.percentile(AR_f8, 50, axis=1), _nt.Array[np.float64]) +assert_type(np.percentile(AR_f8, 50, axis=(1, 0)), _nt.Array[np.float64]) +assert_type(np.percentile(AR_f8, 50, keepdims=True), _nt.Array[np.float64]) +assert_type(np.percentile(AR_f8, 50, axis=0, keepdims=True), _nt.Array[np.float64]) +assert_type(np.percentile(AR_c16, 50), np.complex128) assert_type(np.percentile(AR_m, 50), np.timedelta64) assert_type(np.percentile(AR_M, 50, overwrite_input=True), np.datetime64) assert_type(np.percentile(AR_O, 50), Any) -assert_type(np.percentile(AR_f8, [50]), _nt.Array[np.floating]) -assert_type(np.percentile(AR_c16, [50]), _nt.Array[np.complexfloating]) +assert_type(np.percentile(AR_f8, [50]), _nt.Array[np.float64]) +assert_type(np.percentile(AR_f8, [50], axis=1), _nt.Array[np.float64]) +assert_type(np.percentile(AR_f8, [50], keepdims=True), _nt.Array[np.float64]) +assert_type(np.percentile(AR_c16, [50]), _nt.Array[np.complex128]) assert_type(np.percentile(AR_m, [50]), _nt.Array[np.timedelta64]) assert_type(np.percentile(AR_M, [50], method="nearest"), _nt.Array[np.datetime64]) assert_type(np.percentile(AR_O, [50]), _nt.Array[np.object_]) -assert_type(np.percentile(AR_f8, [50], keepdims=True), Any) -assert_type(np.percentile(AR_f8, [50], axis=[1]), Any) +assert_type(np.percentile(AR_f8, [50], keepdims=True), _nt.Array[np.float64]) assert_type(np.percentile(AR_f8, [50], out=AR_c16), _nt.Array[np.complex128]) -assert_type(np.quantile(AR_f8, 0.5), np.floating) -assert_type(np.quantile(AR_c16, 0.5), np.complexfloating) -assert_type(np.quantile(AR_m, 0.5), np.timedelta64) -assert_type(np.quantile(AR_M, 0.5, overwrite_input=True), np.datetime64) -assert_type(np.quantile(AR_O, 0.5), Any) -assert_type(np.quantile(AR_f8, [0.5]), _nt.Array[np.floating]) -assert_type(np.quantile(AR_c16, [0.5]), _nt.Array[np.complexfloating]) -assert_type(np.quantile(AR_m, [0.5]), _nt.Array[np.timedelta64]) -assert_type(np.quantile(AR_M, [0.5], method="nearest"), _nt.Array[np.datetime64]) -assert_type(np.quantile(AR_O, [0.5]), _nt.Array[np.object_]) -assert_type(np.quantile(AR_f8, [0.5], keepdims=True), Any) -assert_type(np.quantile(AR_f8, [0.5], axis=[1]), Any) -assert_type(np.quantile(AR_f8, [0.5], out=AR_c16), _nt.Array[np.complex128]) +# quantile +assert_type(np.quantile(AR_f8, 0.50), np.float64) +assert_type(np.quantile(AR_f8, 0.50, axis=1), _nt.Array[np.float64]) +assert_type(np.quantile(AR_f8, 0.50, axis=(1, 0)), _nt.Array[np.float64]) +assert_type(np.quantile(AR_f8, 0.50, keepdims=True), _nt.Array[np.float64]) +assert_type(np.quantile(AR_f8, 0.50, axis=0, keepdims=True), _nt.Array[np.float64]) +assert_type(np.quantile(AR_c16, 0.50), np.complex128) +assert_type(np.quantile(AR_m, 0.50), np.timedelta64) +assert_type(np.quantile(AR_M, 0.50, overwrite_input=True), np.datetime64) +assert_type(np.quantile(AR_O, 0.50), Any) +assert_type(np.quantile(AR_f8, [0.50]), _nt.Array[np.float64]) +assert_type(np.quantile(AR_f8, [0.50], axis=1), _nt.Array[np.float64]) +assert_type(np.quantile(AR_f8, [0.50], keepdims=True), _nt.Array[np.float64]) +assert_type(np.quantile(AR_c16, [0.50]), _nt.Array[np.complex128]) +assert_type(np.quantile(AR_m, [0.50]), _nt.Array[np.timedelta64]) +assert_type(np.quantile(AR_M, [0.50], method="nearest"), _nt.Array[np.datetime64]) +assert_type(np.quantile(AR_O, [0.50]), _nt.Array[np.object_]) +assert_type(np.quantile(AR_f8, [0.50], keepdims=True), _nt.Array[np.float64]) +assert_type(np.quantile(AR_f8, [0.50], out=AR_c16), _nt.Array[np.complex128]) assert_type(np.trapezoid(AR_LIKE_i), np.float64) assert_type(np.trapezoid(AR_LIKE_f), np.float64) diff --git a/src/numpy-stubs/@test/static/reject/lib_function_base.pyi b/src/numpy-stubs/@test/static/reject/lib_function_base.pyi index b115ac56..2ef7b9eb 100644 --- a/src/numpy-stubs/@test/static/reject/lib_function_base.pyi +++ b/src/numpy-stubs/@test/static/reject/lib_function_base.pyi @@ -33,16 +33,16 @@ np.average(AR_m) # type: ignore[arg-type] # pyright: ignore[reportArgumentType np.median(AR_M) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] np.percentile(AR_f8, 50j) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] np.quantile(AR_f8, 0.5j) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] -np.percentile(AR_f8, 50, interpolation="bob") # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] -np.quantile(AR_f8, 0.5, interpolation="bob") # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] +np.percentile(AR_f8, 50, interpolation="bob") # type: ignore[call-overload] # pyright: ignore[reportCallIssue] +np.quantile(AR_f8, 0.5, interpolation="bob") # type: ignore[call-overload] # pyright: ignore[reportCallIssue] np.cov(AR_m) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] np.cov(AR_O) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] np.corrcoef(AR_m) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] np.corrcoef(AR_O) # type: ignore[arg-type] # pyright: ignore[reportArgumentType, reportCallIssue] -np.corrcoef(AR_f8, bias=True) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] -np.corrcoef(AR_f8, ddof=2) # type: ignore[call-overload] # pyright: ignore[reportArgumentType, reportCallIssue] +np.corrcoef(AR_f8, bias=True) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] +np.corrcoef(AR_f8, ddof=2) # type: ignore[call-overload] # pyright: ignore[reportCallIssue] np.blackman(1j) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] np.bartlett(1j) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] diff --git a/src/numpy-stubs/@test/static/reject/npyio.pyi b/src/numpy-stubs/@test/static/reject/npyio.pyi index 5a38dccf..350e6ace 100644 --- a/src/numpy-stubs/@test/static/reject/npyio.pyi +++ b/src/numpy-stubs/@test/static/reject/npyio.pyi @@ -10,7 +10,7 @@ pathlib_path: pathlib.Path str_file: IO[str] AR_i8: _nt.Array[np.int64] -np.save(bytes_path, AR_i8) # type: ignore[call-overload] # pyright: ignore[reportArgumentType] +np.save(bytes_path, AR_i8) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] np.savez(bytes_path, AR_i8) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] np.savez_compressed(bytes_path, AR_i8) # type: ignore[arg-type] # pyright: ignore[reportArgumentType] diff --git a/src/numpy-stubs/__init__.pyi b/src/numpy-stubs/__init__.pyi index 53fa2db1..9d22bf4e 100644 --- a/src/numpy-stubs/__init__.pyi +++ b/src/numpy-stubs/__init__.pyi @@ -353,7 +353,6 @@ from .lib import scimath as emath from .lib._arraypad_impl import pad from .lib._arraysetops_impl import ( ediff1d, - in1d, intersect1d, isin, setdiff1d, @@ -399,7 +398,6 @@ from .lib._function_base_impl import ( sinc, sort_complex, trapezoid, - trapz, trim_zeros, unwrap, vectorize, @@ -548,13 +546,13 @@ __all__ = [ # noqa: RUF022 # lib._arraypad_impl.* "pad", # lib._arraysetops_impl.* - "ediff1d", "in1d", "intersect1d", "isin", "setdiff1d", "setxor1d", "union1d", "unique", "unique_all", + "ediff1d", "intersect1d", "isin", "setdiff1d", "setxor1d", "union1d", "unique", "unique_all", "unique_counts", "unique_inverse", "unique_values", # lib._function_base_impl.* "angle", "append", "asarray_chkfinite", "average", "bartlett", "bincount", "blackman", "copy", "corrcoef", "cov", "delete", "diff", "digitize", "extract", "flip", "gradient", "hamming", "hanning", "i0", "insert", "interp", "iterable", "kaiser", "median", "meshgrid", "percentile", "piecewise", "place", "quantile", "rot90", "select", - "sinc", "sort_complex", "trapezoid", "trapz", "trim_zeros", "unwrap", "vectorize", + "sinc", "sort_complex", "trapezoid", "trim_zeros", "unwrap", "vectorize", # lib._histograms_impl.* "histogram", "histogram_bin_edges", "histogramdd", # lib._index_tricks_impl.* diff --git a/src/numpy-stubs/lib/_arraysetops_impl.pyi b/src/numpy-stubs/lib/_arraysetops_impl.pyi index 4ca266f4..543f58d3 100644 --- a/src/numpy-stubs/lib/_arraysetops_impl.pyi +++ b/src/numpy-stubs/lib/_arraysetops_impl.pyi @@ -1,5 +1,5 @@ from typing import Any, Generic, Literal as L, NamedTuple, SupportsIndex as CanIndex, TypeAlias, overload -from typing_extensions import TypeVar, deprecated +from typing_extensions import TypeVar import _numtype as _nt import numpy as np @@ -7,7 +7,6 @@ from numpy._typing import ArrayLike, _ArrayLike __all__ = [ "ediff1d", - "in1d", "intersect1d", "isin", "setdiff1d", @@ -585,14 +584,3 @@ def isin( *, kind: L["sort", "table"] | None = None, ) -> _nt.Array[np.bool]: ... - -# -@deprecated("Use 'isin' instead") -def in1d( - ar1: ArrayLike, - ar2: ArrayLike, - assume_unique: bool = False, - invert: bool = False, - *, - kind: L["sort", "table"] | None = None, -) -> _nt.Array1D[np.bool]: ... diff --git a/src/numpy-stubs/lib/_function_base_impl.pyi b/src/numpy-stubs/lib/_function_base_impl.pyi index 3ec51c09..87ad4dae 100644 --- a/src/numpy-stubs/lib/_function_base_impl.pyi +++ b/src/numpy-stubs/lib/_function_base_impl.pyi @@ -2,6 +2,7 @@ import datetime as dt from _typeshed import Incomplete from collections.abc import Callable, Iterable, Sequence from typing import ( + Any, Concatenate, Final, Literal as L, @@ -13,7 +14,7 @@ from typing import ( overload, type_check_only, ) -from typing_extensions import ParamSpec, TypeIs, TypeVar, deprecated +from typing_extensions import ParamSpec, TypeIs, TypeVar import _numtype as _nt import numpy as np @@ -57,7 +58,6 @@ __all__ = [ "sinc", "sort_complex", "trapezoid", - "trapz", "trim_zeros", "unwrap", "vectorize", @@ -75,6 +75,7 @@ _ScalarT = TypeVar("_ScalarT", bound=np.generic) _ScalarT1 = TypeVar("_ScalarT1", bound=np.generic) _ScalarT2 = TypeVar("_ScalarT2", bound=np.generic) _NumberT = TypeVar("_NumberT", bound=np.number) +_InexactDateTimeT = TypeVar("_InexactDateTimeT", bound=np.inexact | np.timedelta64 | np.datetime64) _TrapezoidScalarT = TypeVar("_TrapezoidScalarT", bound=np.inexact | np.timedelta64) _Tuple2: TypeAlias = tuple[_T, _T] @@ -628,14 +629,12 @@ def cov( dtype: DTypeLike, ) -> _nt.Array[Incomplete]: ... -# NOTE `bias` and `ddof` are deprecated and ignored +# @overload def corrcoef( x: _nt.CoFloat64_1nd, y: _nt.CoFloat64_1nd | None = None, rowvar: bool = True, - bias: _NoValueType = ..., - ddof: _NoValueType = ..., *, dtype: _nt.ToDTypeFloat64 | None = None, ) -> _nt.Array[np.float64]: ... @@ -644,28 +643,18 @@ def corrcoef( x: _nt.ToLongDouble_1nd, y: _nt.CoFloating_1nd | None = None, rowvar: bool = True, - bias: _NoValueType = ..., - ddof: _NoValueType = ..., *, dtype: _nt.ToDTypeLongDouble | None = None, ) -> _nt.Array[np.longdouble]: ... @overload def corrcoef( - x: _nt.CoFloating_1nd, - y: _nt.ToLongDouble_1nd, - rowvar: bool = True, - bias: _NoValueType = ..., - ddof: _NoValueType = ..., - *, - dtype: _nt.ToDTypeLongDouble | None = None, + x: _nt.CoFloating_1nd, y: _nt.ToLongDouble_1nd, rowvar: bool = True, *, dtype: _nt.ToDTypeLongDouble | None = None ) -> _nt.Array[np.longdouble]: ... @overload def corrcoef( x: _nt.ToComplex128_1nd | _nt.ToComplex64_1nd, y: _nt.CoComplex128_1nd | None = None, rowvar: bool = True, - bias: _NoValueType = ..., - ddof: _NoValueType = ..., *, dtype: _nt.ToDTypeComplex128 | None = None, ) -> _nt.Array[np.complex128]: ... @@ -674,8 +663,6 @@ def corrcoef( x: _nt.CoComplex128_1nd, y: _nt.ToComplex128_1nd | _nt.ToComplex64_1nd, rowvar: bool = True, - bias: _NoValueType = ..., - ddof: _NoValueType = ..., *, dtype: _nt.ToDTypeComplex128 | None = None, ) -> _nt.Array[np.complex128]: ... @@ -684,40 +671,20 @@ def corrcoef( x: _nt.ToCLongDouble_1nd, y: _nt.CoComplex_1nd | None = None, rowvar: bool = True, - bias: _NoValueType = ..., - ddof: _NoValueType = ..., *, dtype: _nt.ToDTypeCLongDouble | None = None, ) -> _nt.Array[np.clongdouble]: ... @overload def corrcoef( - x: _nt.CoComplex_1nd, - y: _nt.ToCLongDouble_1nd, - rowvar: bool = True, - bias: _NoValueType = ..., - ddof: _NoValueType = ..., - *, - dtype: _nt.ToDTypeCLongDouble | None = None, + x: _nt.CoComplex_1nd, y: _nt.ToCLongDouble_1nd, rowvar: bool = True, *, dtype: _nt.ToDTypeCLongDouble | None = None ) -> _nt.Array[np.clongdouble]: ... @overload def corrcoef( - x: _nt.CoComplex_1nd, - y: _nt.CoComplex_1nd | None = None, - rowvar: bool = True, - bias: _NoValueType = ..., - ddof: _NoValueType = ..., - *, - dtype: _DTypeLike[_ScalarT], + x: _nt.CoComplex_1nd, y: _nt.CoComplex_1nd | None = None, rowvar: bool = True, *, dtype: _DTypeLike[_ScalarT] ) -> _nt.Array[_ScalarT]: ... @overload def corrcoef( - x: _nt.CoComplex_1nd, - y: _nt.CoComplex_1nd | None = None, - rowvar: bool = True, - bias: _NoValueType = ..., - ddof: _NoValueType = ..., - *, - dtype: DTypeLike | None = None, + x: _nt.CoComplex_1nd, y: _nt.CoComplex_1nd | None = None, rowvar: bool = True, *, dtype: DTypeLike | None = None ) -> _nt.Array[Incomplete]: ... # @@ -785,12 +752,10 @@ def median( keepdims: bool = False, ) -> _ArrayT: ... -# keep in sync with `lib._nanfunctions_impl.nanpercentile` -# TODO(jorenham): deprecate interpolation -# TODO(jorenham): deprecate only allow weights if method="inverted_cdf" -@overload +# NOTE: keep in sync with `quantile` +@overload # inexact, scalar, axis=None def percentile( - a: _nt.CoFloating_nd, + a: _ArrayLike[_InexactDateTimeT], q: _nt.CoFloating_0d, axis: None = None, out: None = None, @@ -799,25 +764,35 @@ def percentile( keepdims: L[False] = False, *, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> np.floating: ... -@overload +) -> _InexactDateTimeT: ... +@overload # inexact, scalar, axis= def percentile( - a: _nt.CoFloating_nd, - q: _nt.CoFloating_1nd, - axis: None = None, + a: _ArrayLike[_InexactDateTimeT], + q: _nt.CoFloating_0d, + axis: _ShapeLike, out: None = None, overwrite_input: bool = False, method: _PercentileMethod = "linear", keepdims: L[False] = False, *, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> _nt.Array[np.floating]: ... -@overload +) -> _nt.Array[_InexactDateTimeT]: ... +@overload # inexact, scalar, keepdims=True def percentile( - a: _nt.ToComplex_nd, + a: _ArrayLike[_InexactDateTimeT], q: _nt.CoFloating_0d, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + *, + keepdims: L[True], + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[_InexactDateTimeT]: ... +@overload # inexact, array, axis=None +def percentile( + a: _ArrayLike[_InexactDateTimeT], + q: _nt.Array[_nt.co_float, _ShapeT], axis: None = None, out: None = None, overwrite_input: bool = False, @@ -825,12 +800,23 @@ def percentile( keepdims: L[False] = False, *, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> np.complexfloating: ... -@overload +) -> _nt.Array[_InexactDateTimeT, _ShapeT]: ... +@overload # inexact, array-like def percentile( - a: _nt.ToComplex_nd, + a: _ArrayLike[_InexactDateTimeT], q: _nt.CoFloating_1nd, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: bool = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[_InexactDateTimeT]: ... +@overload # float, scalar, axis=None +def percentile( + a: _nt.CastsArray[np.float64], + q: _nt.CoFloating_0d, axis: None = None, out: None = None, overwrite_input: bool = False, @@ -838,12 +824,35 @@ def percentile( keepdims: L[False] = False, *, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> _nt.Array[np.complexfloating]: ... -@overload +) -> np.float64: ... +@overload # float, scalar, axis= def percentile( - a: _nt.ToTimeDelta_nd, + a: _nt.CastsArray[np.float64], q: _nt.CoFloating_0d, + axis: _ShapeLike, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.float64]: ... +@overload # float, scalar, keepdims=True +def percentile( + a: _nt.CastsArray[np.float64], + q: _nt.CoFloating_0d, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + *, + keepdims: L[True], + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.float64]: ... +@overload # float, array, axis=None +def percentile( + a: _nt.CastsArray[np.float64], + q: _nt.Array[_nt.co_float, _ShapeT], axis: None = None, out: None = None, overwrite_input: bool = False, @@ -851,12 +860,23 @@ def percentile( keepdims: L[False] = False, *, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> np.timedelta64: ... -@overload +) -> _nt.Array[np.float64, _ShapeT]: ... +@overload # float, array-like def percentile( - a: _nt.ToTimeDelta_nd, + a: _nt.CastsArray[np.float64], q: _nt.CoFloating_1nd, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: bool = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.float64]: ... +@overload # complex, scalar, axis=None +def percentile( + a: _nt.ToComplex128_1nd, + q: _nt.CoFloating_0d, axis: None = None, out: None = None, overwrite_input: bool = False, @@ -864,12 +884,35 @@ def percentile( keepdims: L[False] = False, *, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> _nt.Array[np.timedelta64]: ... -@overload +) -> np.complex128: ... +@overload # complex, scalar, axis= def percentile( - a: _nt.ToDateTime_nd, + a: _nt.ToComplex128_1nd, q: _nt.CoFloating_0d, + axis: _ShapeLike, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.complex128]: ... +@overload # complex, scalar, keepdims=True +def percentile( + a: _nt.ToComplex128_1nd, + q: _nt.CoFloating_0d, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + *, + keepdims: L[True], + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.complex128]: ... +@overload # complex, array, axis=None +def percentile( + a: _nt.ToComplex128_1nd, + q: _nt.Array[_nt.co_float, _ShapeT], axis: None = None, out: None = None, overwrite_input: bool = False, @@ -877,12 +920,23 @@ def percentile( keepdims: L[False] = False, *, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> np.datetime64: ... -@overload +) -> _nt.Array[np.complex128, _ShapeT]: ... +@overload # complex, array-like def percentile( - a: _nt.ToDateTime_nd, + a: _nt.ToComplex128_1nd, q: _nt.CoFloating_1nd, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: bool = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.complex128]: ... +@overload # object_, scalar, axis=None +def percentile( + a: _nt.ToObject_1nd, + q: _nt.CoFloating_0d, axis: None = None, out: None = None, overwrite_input: bool = False, @@ -890,25 +944,35 @@ def percentile( keepdims: L[False] = False, *, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> _nt.Array[np.datetime64]: ... -@overload +) -> Any: ... +@overload # object_, scalar, axis= def percentile( - a: _nt.ToObject_nd, + a: _nt.ToObject_1nd, q: _nt.CoFloating_0d, - axis: None = None, + axis: _ShapeLike, out: None = None, overwrite_input: bool = False, method: _PercentileMethod = "linear", keepdims: L[False] = False, *, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> Incomplete: ... -@overload +) -> _nt.Array[np.object_]: ... +@overload # object_, scalar, keepdims=True def percentile( - a: _nt.ToObject_nd, - q: _nt.CoFloating_1nd, + a: _nt.ToObject_1nd, + q: _nt.CoFloating_0d, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + *, + keepdims: L[True], + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.object_]: ... +@overload # object_, array, axis=None +def percentile( + a: _nt.ToObject_1nd, + q: _nt.Array[_nt.co_float, _ShapeT], axis: None = None, out: None = None, overwrite_input: bool = False, @@ -916,11 +980,10 @@ def percentile( keepdims: L[False] = False, *, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> _nt.Array[np.object_]: ... -@overload +) -> _nt.Array[np.object_, _ShapeT]: ... +@overload # object_, array-like def percentile( - a: _nt.CoComplex_nd | _nt.CoDateTime_nd | _nt.ToObject_nd, + a: _nt.ToObject_1nd, q: _nt.CoFloating_1nd, axis: _ShapeLike | None = None, out: None = None, @@ -929,11 +992,22 @@ def percentile( keepdims: bool = False, *, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> Incomplete: ... -@overload +) -> _nt.Array[np.object_]: ... +@overload # out= (keyword) def percentile( - a: _nt.CoComplex_nd | _nt.CoDateTime_nd | _nt.ToObject_nd, + a: ArrayLike, + q: _nt.CoFloating_1nd, + axis: _ShapeLike | None, + out: _ArrayT, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: bool = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _ArrayT: ... +@overload # out= (positional) +def percentile( + a: ArrayLike, q: _nt.CoFloating_1nd, axis: _ShapeLike | None = None, *, @@ -942,11 +1016,264 @@ def percentile( method: _PercentileMethod = "linear", keepdims: bool = False, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, ) -> _ArrayT: ... -@overload +@overload # fallback def percentile( - a: _nt.CoComplex_nd | _nt.CoDateTime_nd | _nt.ToObject_nd, + a: _nt.CoComplex_1nd | _nt.ToObject_1nd, + q: _nt.CoFloating_1nd, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: bool = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> Incomplete: ... + +# NOTE: keep in sync with `percentile` +@overload # inexact, scalar, axis=None +def quantile( + a: _ArrayLike[_InexactDateTimeT], + q: _nt.CoFloating_0d, + axis: None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _InexactDateTimeT: ... +@overload # inexact, scalar, axis= +def quantile( + a: _ArrayLike[_InexactDateTimeT], + q: _nt.CoFloating_0d, + axis: _ShapeLike, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[_InexactDateTimeT]: ... +@overload # inexact, scalar, keepdims=True +def quantile( + a: _ArrayLike[_InexactDateTimeT], + q: _nt.CoFloating_0d, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + *, + keepdims: L[True], + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[_InexactDateTimeT]: ... +@overload # inexact, array, axis=None +def quantile( + a: _ArrayLike[_InexactDateTimeT], + q: _nt.Array[_nt.co_float, _ShapeT], + axis: None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[_InexactDateTimeT, _ShapeT]: ... +@overload # inexact, array-like +def quantile( + a: _ArrayLike[_InexactDateTimeT], + q: _nt.CoFloating_1nd, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: bool = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[_InexactDateTimeT]: ... +@overload # float, scalar, axis=None +def quantile( + a: _nt.CastsArray[np.float64], + q: _nt.CoFloating_0d, + axis: None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> np.float64: ... +@overload # float, scalar, axis= +def quantile( + a: _nt.CastsArray[np.float64], + q: _nt.CoFloating_0d, + axis: _ShapeLike, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.float64]: ... +@overload # float, scalar, keepdims=True +def quantile( + a: _nt.CastsArray[np.float64], + q: _nt.CoFloating_0d, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + *, + keepdims: L[True], + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.float64]: ... +@overload # float, array, axis=None +def quantile( + a: _nt.CastsArray[np.float64], + q: _nt.Array[_nt.co_float, _ShapeT], + axis: None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.float64, _ShapeT]: ... +@overload # float, array-like +def quantile( + a: _nt.CastsArray[np.float64], + q: _nt.CoFloating_1nd, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: bool = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.float64]: ... +@overload # complex, scalar, axis=None +def quantile( + a: _nt.ToComplex128_1nd, + q: _nt.CoFloating_0d, + axis: None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> np.complex128: ... +@overload # complex, scalar, axis= +def quantile( + a: _nt.ToComplex128_1nd, + q: _nt.CoFloating_0d, + axis: _ShapeLike, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.complex128]: ... +@overload # complex, scalar, keepdims=True +def quantile( + a: _nt.ToComplex128_1nd, + q: _nt.CoFloating_0d, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + *, + keepdims: L[True], + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.complex128]: ... +@overload # complex, array, axis=None +def quantile( + a: _nt.ToComplex128_1nd, + q: _nt.Array[_nt.co_float, _ShapeT], + axis: None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.complex128, _ShapeT]: ... +@overload # complex, array-like +def quantile( + a: _nt.ToComplex128_1nd, + q: _nt.CoFloating_1nd, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: bool = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.complex128]: ... +@overload # object_, scalar, axis=None +def quantile( + a: _nt.ToObject_1nd, + q: _nt.CoFloating_0d, + axis: None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> Any: ... +@overload # object_, scalar, axis= +def quantile( + a: _nt.ToObject_1nd, + q: _nt.CoFloating_0d, + axis: _ShapeLike, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.object_]: ... +@overload # object_, scalar, keepdims=True +def quantile( + a: _nt.ToObject_1nd, + q: _nt.CoFloating_0d, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + *, + keepdims: L[True], + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.object_]: ... +@overload # object_, array, axis=None +def quantile( + a: _nt.ToObject_1nd, + q: _nt.Array[_nt.co_float, _ShapeT], + axis: None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: L[False] = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.object_, _ShapeT]: ... +@overload # object_, array-like +def quantile( + a: _nt.ToObject_1nd, + q: _nt.CoFloating_1nd, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: bool = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> _nt.Array[np.object_]: ... +@overload # out= (keyword) +def quantile( + a: ArrayLike, q: _nt.CoFloating_1nd, axis: _ShapeLike | None, out: _ArrayT, @@ -955,12 +1282,33 @@ def percentile( keepdims: bool = False, *, weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, ) -> _ArrayT: ... +@overload # out= (positional) +def quantile( + a: ArrayLike, + q: _nt.CoFloating_1nd, + axis: _ShapeLike | None = None, + *, + out: _ArrayT, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: bool = False, + weights: _nt.CoFloating_1nd | None = None, +) -> _ArrayT: ... +@overload # fallback +def quantile( + a: _nt.CoComplex_1nd | _nt.ToObject_1nd, + q: _nt.CoFloating_1nd, + axis: _ShapeLike | None = None, + out: None = None, + overwrite_input: bool = False, + method: _PercentileMethod = "linear", + keepdims: bool = False, + *, + weights: _nt.CoFloating_1nd | None = None, +) -> Incomplete: ... -# NOTE: Not an alias, but they do have identical signatures (that we can reuse) -quantile = percentile - +# @overload # workaround for microsoft/pyright#10232 def trapezoid( y: _nt._ToArray_nnd[np.float64 | _nt.co_integer], @@ -1105,10 +1453,6 @@ def trapezoid( axis: CanIndex = -1, ) -> Incomplete: ... -# -@deprecated("Use 'trapezoid' instead") -def trapz(y: ArrayLike, x: ArrayLike | None = None, dx: float = 1.0, axis: int = -1) -> Incomplete: ... - # @overload def meshgrid(*, copy: bool = True, sparse: bool = False, indexing: _Indexing = "xy") -> tuple[()]: ... diff --git a/src/numpy-stubs/lib/_index_tricks_impl.pyi b/src/numpy-stubs/lib/_index_tricks_impl.pyi index aac54d33..75726ac5 100644 --- a/src/numpy-stubs/lib/_index_tricks_impl.pyi +++ b/src/numpy-stubs/lib/_index_tricks_impl.pyi @@ -1,4 +1,4 @@ -from _typeshed import Incomplete +from _typeshed import Incomplete, SupportsLenAndGetItem from collections.abc import Sequence from typing import ( Any, @@ -12,12 +12,13 @@ from typing import ( final, overload, ) -from typing_extensions import TypeVar, deprecated +from typing_extensions import TypeVar import _numtype as _nt import numpy as np +from numpy import _CastingKind # noqa: ICN003 from numpy._core.multiarray import ravel_multi_index, unravel_index -from numpy._typing import ArrayLike, _SupportsDType as _HasDType +from numpy._typing import ArrayLike, DTypeLike, _ArrayLike, _DTypeLike, _SupportsDType as _HasDType __all__ = [ "c_", @@ -94,8 +95,6 @@ class ndindex: # def __iter__(self) -> Self: ... def __next__(self) -> tuple[int, ...]: ... - @deprecated("Deprecated since 1.20.0.") - def ndincr(self, /) -> None: ... class nd_grid(Generic[_BoolT_co]): __slots__: ClassVar[tuple[str, ...]] = ("sparse",) @@ -139,17 +138,62 @@ class AxisConcatenator(Generic[_AxisT_co, _MatrixT_co, _NDMinT_co, _Trans1DT_co] def __len__(self, /) -> L[0]: ... # + # Keep in sync with _core.multiarray.concatenate @staticmethod @overload def concatenate( - *a: _nt._ToArray_nd[_ScalarT], axis: CanIndex | None = 0, out: None = None + arrays: _ArrayLike[_ScalarT], + /, + axis: CanIndex | None = 0, + out: None = None, + *, + dtype: None = None, + casting: _CastingKind | None = "same_kind", ) -> _nt.Array[_ScalarT]: ... @staticmethod @overload - def concatenate(*a: ArrayLike, axis: CanIndex | None = 0, out: _ArrayT) -> _ArrayT: ... + def concatenate( + arrays: SupportsLenAndGetItem[ArrayLike], + /, + axis: CanIndex | None = 0, + out: None = None, + *, + dtype: _DTypeLike[_ScalarT], + casting: _CastingKind | None = "same_kind", + ) -> _nt.Array[_ScalarT]: ... + @staticmethod + @overload + def concatenate( + arrays: SupportsLenAndGetItem[ArrayLike], + /, + axis: CanIndex | None = 0, + out: None = None, + *, + dtype: DTypeLike | None = None, + casting: _CastingKind | None = "same_kind", + ) -> _nt.Array[Incomplete]: ... @staticmethod @overload - def concatenate(*a: ArrayLike, axis: CanIndex | None = 0, out: None = None) -> _nt.Array: ... + def concatenate( + arrays: SupportsLenAndGetItem[ArrayLike], + /, + axis: CanIndex | None = 0, + *, + out: _ArrayT, + dtype: DTypeLike | None = None, + casting: _CastingKind | None = "same_kind", + ) -> _ArrayT: ... + @staticmethod + @overload + def concatenate( + arrays: SupportsLenAndGetItem[ArrayLike], + /, + axis: CanIndex | None, + out: _ArrayT, + *, + dtype: DTypeLike | None = None, + casting: _CastingKind | None = "same_kind", + ) -> _ArrayT: ... @final class RClass(AxisConcatenator[L[0], L[False], L[1], L[-1]]): diff --git a/src/numpy-stubs/lib/_nanfunctions_impl.pyi b/src/numpy-stubs/lib/_nanfunctions_impl.pyi index 47e6c589..666edba7 100644 --- a/src/numpy-stubs/lib/_nanfunctions_impl.pyi +++ b/src/numpy-stubs/lib/_nanfunctions_impl.pyi @@ -1,26 +1,5 @@ -from _typeshed import Incomplete -from typing import Any, Literal as L, overload -from typing_extensions import TypeVar - -import _numtype as _nt -import numpy as np -from numpy._core.fromnumeric import ( - amax as nanmax, - amin as nanmin, - argmax as nanargmax, - argmin as nanargmin, - cumprod as nancumprod, - cumsum as nancumsum, - mean as nanmean, - prod as nanprod, - std as nanstd, - sum as nansum, - var as nanvar, -) -from numpy._globals import _NoValueType -from numpy._typing import _ShapeLike - -from ._function_base_impl import _PercentileMethod +from numpy._core.fromnumeric import amax, amin, argmax, argmin, cumprod, cumsum, mean, prod, std, sum, var +from numpy.lib._function_base_impl import median, percentile, quantile __all__ = [ "nanargmax", @@ -39,240 +18,19 @@ __all__ = [ "nanvar", ] -### - -_ArrayT = TypeVar("_ArrayT", bound=_nt.Array) - -### - -# keep in sync with `lib._function_base_impl.median` -@overload -def nanmedian( - a: _nt.CoFloating_nd, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - keepdims: _NoValueType | L[False] = ..., -) -> np.floating: ... -@overload -def nanmedian( - a: _nt.ToComplex_nd, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - keepdims: _NoValueType | L[False] = ..., -) -> np.complexfloating: ... -@overload -def nanmedian( - a: _nt.ToTimeDelta_nd, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - keepdims: _NoValueType | L[False] = ..., -) -> np.timedelta64: ... -@overload -def nanmedian( - a: _nt.ToObject_nd, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - keepdims: _NoValueType | L[False] = ..., -) -> Incomplete: ... -@overload -def nanmedian( - a: _nt.CoComplex_nd | _nt.CoTimeDelta_nd | _nt.ToObject_nd, - axis: _ShapeLike | None = None, - out: None = None, - overwrite_input: bool = False, - keepdims: _NoValueType | bool = ..., -) -> Incomplete: ... -@overload -def nanmedian( - a: _nt.CoComplex_nd | _nt.CoTimeDelta_nd | _nt.ToObject_nd, - axis: _ShapeLike | None, - out: _ArrayT, - overwrite_input: bool = False, - keepdims: _NoValueType | bool = ..., -) -> _ArrayT: ... -@overload -def nanmedian( - a: _nt.CoComplex_nd | _nt.CoTimeDelta_nd | _nt.ToObject_nd, - axis: _ShapeLike | None = None, - *, - out: _ArrayT, - overwrite_input: bool = False, - keepdims: _NoValueType | bool = ..., -) -> _ArrayT: ... - -# keep in sync with `lib._function_base_impl.percentile` -@overload -def nanpercentile( - a: _nt.CoFloating_nd, - q: _nt.CoFloating_0d, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | L[False] = ..., - *, - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> np.floating: ... -@overload -def nanpercentile( - a: _nt.CoFloating_nd, - q: _nt.CoFloating_1nd, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | L[False] = ..., - *, - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> _nt.Array[np.floating]: ... -@overload -def nanpercentile( - a: _nt.ToComplex_nd, - q: _nt.CoFloating_0d, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | L[False] = ..., - *, - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> np.complexfloating: ... -@overload -def nanpercentile( - a: _nt.ToComplex_nd, - q: _nt.CoFloating_1nd, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | L[False] = ..., - *, - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> _nt.Array[np.complexfloating]: ... -@overload -def nanpercentile( - a: _nt.ToTimeDelta_nd, - q: _nt.CoFloating_0d, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | L[False] = ..., - *, - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> np.timedelta64: ... -@overload -def nanpercentile( - a: _nt.ToTimeDelta_nd, - q: _nt.CoFloating_1nd, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | L[False] = ..., - *, - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> _nt.Array[np.timedelta64]: ... -@overload -def nanpercentile( - a: _nt.ToDateTime_nd, - q: _nt.CoFloating_0d, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | L[False] = ..., - *, - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> np.datetime64: ... -@overload -def nanpercentile( - a: _nt.ToDateTime_nd, - q: _nt.CoFloating_1nd, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | L[False] = ..., - *, - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> _nt.Array[np.datetime64]: ... -@overload -def nanpercentile( - a: _nt.ToObject_nd, - q: _nt.CoFloating_0d, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | L[False] = ..., - *, - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> Any: ... -@overload -def nanpercentile( - a: _nt.ToObject_nd, - q: _nt.CoFloating_1nd, - axis: None = None, - out: None = None, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | L[False] = ..., - *, - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> _nt.Array[np.object_]: ... -@overload -def nanpercentile( - a: _nt.CoComplex_nd | _nt.CoDateTime_nd | _nt.ToObject_nd, - q: _nt.CoFloating_1nd, - axis: _ShapeLike | None = None, - out: None = None, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | bool = ..., - *, - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> Any: ... -@overload -def nanpercentile( - a: _nt.CoComplex_nd | _nt.CoDateTime_nd | _nt.ToObject_nd, - q: _nt.CoFloating_1nd, - axis: _ShapeLike | None = None, - *, - out: _ArrayT, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | bool = ..., - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> _ArrayT: ... -@overload -def nanpercentile( - a: _nt.CoComplex_nd | _nt.CoDateTime_nd | _nt.ToObject_nd, - q: _nt.CoFloating_1nd, - axis: _ShapeLike | None, - out: _ArrayT, - overwrite_input: bool = False, - method: _PercentileMethod = "linear", - keepdims: _NoValueType | bool = ..., - *, - weights: _nt.CoFloating_1nd | None = None, - interpolation: None = None, -) -> _ArrayT: ... - -nanquantile = nanpercentile +# NOTE: In reality these functions are not aliases but distinct functions +# with identical signatures. +nanmin = amin +nanmax = amax +nanargmin = argmin +nanargmax = argmax +nansum = sum +nanprod = prod +nancumsum = cumsum +nancumprod = cumprod +nanmean = mean +nanvar = var +nanstd = std +nanmedian = median +nanpercentile = percentile +nanquantile = quantile diff --git a/src/numpy-stubs/lib/_npyio_impl.pyi b/src/numpy-stubs/lib/_npyio_impl.pyi index ac3f36f4..e2d8c8c7 100644 --- a/src/numpy-stubs/lib/_npyio_impl.pyi +++ b/src/numpy-stubs/lib/_npyio_impl.pyi @@ -4,12 +4,11 @@ from _typeshed import Incomplete, StrOrBytesPath, StrPath, SupportsKeysAndGetIte from collections.abc import Callable, Collection, Iterable, Iterator, Mapping, Sequence from re import Pattern from typing import IO, Any, ClassVar, Generic, Literal as L, Protocol, Self, TypeAlias, overload, type_check_only -from typing_extensions import TypeVar, deprecated, override +from typing_extensions import TypeVar, override import _numtype as _nt import numpy as np from numpy._core.multiarray import packbits, unpackbits -from numpy._globals import _NoValueType from numpy._typing import ArrayLike, DTypeLike, _DTypeLike, _SupportsArrayFunc from numpy.ma.mrecords import MaskedRecords @@ -117,19 +116,8 @@ def load( ) -> Any: ... # -@overload -def save(file: _FNameWrite, arr: ArrayLike, allow_pickle: bool = True, fix_imports: _NoValueType = ...) -> None: ... -@overload -@deprecated("The 'fix_imports' flag is deprecated in NumPy 2.1.") -def save(file: _FNameWrite, arr: ArrayLike, allow_pickle: bool, fix_imports: bool) -> None: ... -@overload -@deprecated("The 'fix_imports' flag is deprecated in NumPy 2.1.") -def save(file: _FNameWrite, arr: ArrayLike, allow_pickle: bool = True, *, fix_imports: bool) -> None: ... - -# +def save(file: _FNameWrite, arr: ArrayLike, allow_pickle: bool = True) -> None: ... def savez(file: _FNameWrite, *args: ArrayLike, allow_pickle: bool = True, **kwds: ArrayLike) -> None: ... - -# def savez_compressed(file: _FNameWrite, *args: ArrayLike, allow_pickle: bool = True, **kwds: ArrayLike) -> None: ... # File-like objects only have to implement `__iter__` and, diff --git a/src/numpy-stubs/lib/mixins.pyi b/src/numpy-stubs/lib/mixins.pyi index 1f3f6730..349facce 100644 --- a/src/numpy-stubs/lib/mixins.pyi +++ b/src/numpy-stubs/lib/mixins.pyi @@ -19,8 +19,6 @@ _AnyArray: TypeAlias = np.ndarray[Any, np.dtype] # As such, only little type safety can be provided here. class NDArrayOperatorsMixin(Generic[_T_contra, _T_co]): - from numpy._core import umath as um # noqa: PLC0415 - __slots__ = () @type_check_only diff --git a/src/numpy-stubs/matlib.pyi b/src/numpy-stubs/matlib.pyi index b317b407..a0af92e0 100644 --- a/src/numpy-stubs/matlib.pyi +++ b/src/numpy-stubs/matlib.pyi @@ -227,7 +227,6 @@ from numpy import ( i0, iinfo, imag, - in1d, index_exp, indices, inexact, @@ -457,7 +456,6 @@ from numpy import ( trace, transpose, trapezoid, - trapz, tri, tril, tril_indices, @@ -555,13 +553,13 @@ __all__ += [ # noqa: RUF022 # lib._arraypad_impl.* "pad", # lib._arraysetops_impl.* - "ediff1d", "in1d", "intersect1d", "isin", "setdiff1d", "setxor1d", "union1d", "unique", "unique_all", + "ediff1d", "intersect1d", "isin", "setdiff1d", "setxor1d", "union1d", "unique", "unique_all", "unique_counts", "unique_inverse", "unique_values", # lib._function_base_impl.* "angle", "append", "asarray_chkfinite", "average", "bartlett", "bincount", "blackman", "copy", "corrcoef", "cov", "delete", "diff", "digitize", "extract", "flip", "gradient", "hamming", "hanning", "i0", "insert", "interp", "iterable", "kaiser", "median", "meshgrid", "percentile", "piecewise", "place", "quantile", "rot90", "select", - "sinc", "sort_complex", "trapezoid", "trapz", "trim_zeros", "unwrap", "vectorize", + "sinc", "sort_complex", "trapezoid", "trim_zeros", "unwrap", "vectorize", # lib._histograms_impl.* "histogram", "histogram_bin_edges", "histogramdd", # lib._index_tricks_impl.* diff --git a/tool/allowlists/todo.txt b/tool/allowlists/todo.txt index 59c630a5..be55ce32 100644 --- a/tool/allowlists/todo.txt +++ b/tool/allowlists/todo.txt @@ -1,18 +1,5 @@ -numpy.corrcoef numpy.f2py._backends._meson.MesonTemplate.objects_substitution numpy.fft.helper -numpy.in1d -numpy.lib._arraysetops_impl.__all__ -numpy.lib._arraysetops_impl.in1d -numpy.lib._function_base_impl.__all__ -numpy.lib._function_base_impl.corrcoef -numpy.lib._function_base_impl.percentile -numpy.lib._function_base_impl.trapz -numpy.lib._index_tricks_impl.AxisConcatenator.concatenate -numpy.lib._index_tricks_impl.ndindex.ndincr -numpy.lib._nanfunctions_impl.nanpercentile -numpy.lib._npyio_impl.save -numpy.lib.mixins.NDArrayOperatorsMixin.um numpy.linalg.linalg numpy.ma.all numpy.ma.anom @@ -124,15 +111,3 @@ numpy.ma.var numpy.ma.vstack numpy.ma.zeros numpy.ma.zeros_like -numpy.matlib.corrcoef -numpy.matlib.in1d -numpy.matlib.nanpercentile -numpy.matlib.ndindex.ndincr -numpy.matlib.percentile -numpy.matlib.save -numpy.matlib.trapz -numpy.nanpercentile -numpy.ndindex.ndincr -numpy.percentile -numpy.save -numpy.trapz