From 6faac59fab173b24759037b8a3be3944f7546812 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 23 Dec 2025 16:43:18 +0100 Subject: [PATCH 01/11] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20`in1d`=20remove?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/__init__.pyi | 3 +-- src/numpy-stubs/lib/_arraysetops_impl.pyi | 14 +------------- src/numpy-stubs/matlib.pyi | 3 +-- tool/allowlists/todo.txt | 4 ---- 4 files changed, 3 insertions(+), 21 deletions(-) diff --git a/src/numpy-stubs/__init__.pyi b/src/numpy-stubs/__init__.pyi index 53fa2db1..4798bee0 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, @@ -548,7 +547,7 @@ __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", 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/matlib.pyi b/src/numpy-stubs/matlib.pyi index b317b407..cd793400 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, @@ -555,7 +554,7 @@ __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", diff --git a/tool/allowlists/todo.txt b/tool/allowlists/todo.txt index 59c630a5..ae8f2ca4 100644 --- a/tool/allowlists/todo.txt +++ b/tool/allowlists/todo.txt @@ -1,9 +1,6 @@ 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 @@ -125,7 +122,6 @@ 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 From abacc8e7940a12981332e4725b62ab7631f425ab Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 23 Dec 2025 16:49:24 +0100 Subject: [PATCH 02/11] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20`trapz`:=20remove?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/__init__.pyi | 3 +-- src/numpy-stubs/lib/_function_base_impl.pyi | 7 +------ src/numpy-stubs/matlib.pyi | 3 +-- tool/allowlists/todo.txt | 4 ---- 4 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/numpy-stubs/__init__.pyi b/src/numpy-stubs/__init__.pyi index 4798bee0..9d22bf4e 100644 --- a/src/numpy-stubs/__init__.pyi +++ b/src/numpy-stubs/__init__.pyi @@ -398,7 +398,6 @@ from .lib._function_base_impl import ( sinc, sort_complex, trapezoid, - trapz, trim_zeros, unwrap, vectorize, @@ -553,7 +552,7 @@ __all__ = [ # noqa: RUF022 "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/_function_base_impl.pyi b/src/numpy-stubs/lib/_function_base_impl.pyi index 3ec51c09..899fb043 100644 --- a/src/numpy-stubs/lib/_function_base_impl.pyi +++ b/src/numpy-stubs/lib/_function_base_impl.pyi @@ -13,7 +13,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 +57,6 @@ __all__ = [ "sinc", "sort_complex", "trapezoid", - "trapz", "trim_zeros", "unwrap", "vectorize", @@ -1105,10 +1104,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/matlib.pyi b/src/numpy-stubs/matlib.pyi index cd793400..a0af92e0 100644 --- a/src/numpy-stubs/matlib.pyi +++ b/src/numpy-stubs/matlib.pyi @@ -456,7 +456,6 @@ from numpy import ( trace, transpose, trapezoid, - trapz, tri, tril, tril_indices, @@ -560,7 +559,7 @@ __all__ += [ # noqa: RUF022 "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 ae8f2ca4..50aeaf92 100644 --- a/tool/allowlists/todo.txt +++ b/tool/allowlists/todo.txt @@ -1,10 +1,8 @@ numpy.corrcoef numpy.f2py._backends._meson.MesonTemplate.objects_substitution numpy.fft.helper -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 @@ -126,9 +124,7 @@ 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 From 8420005bf222a883d49713b034aa9eedeef6b3f8 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 23 Dec 2025 16:52:21 +0100 Subject: [PATCH 03/11] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20`corrcoef`:=20rem?= =?UTF-8?q?ove=20`bias`=20and=20`ddof`=20params?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/lib/_function_base_impl.pyi | 44 +++------------------ tool/allowlists/todo.txt | 3 -- 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/src/numpy-stubs/lib/_function_base_impl.pyi b/src/numpy-stubs/lib/_function_base_impl.pyi index 899fb043..bf8a3f8e 100644 --- a/src/numpy-stubs/lib/_function_base_impl.pyi +++ b/src/numpy-stubs/lib/_function_base_impl.pyi @@ -627,14 +627,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]: ... @@ -643,28 +641,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]: ... @@ -673,8 +661,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]: ... @@ -683,40 +669,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]: ... # diff --git a/tool/allowlists/todo.txt b/tool/allowlists/todo.txt index 50aeaf92..fffbfd26 100644 --- a/tool/allowlists/todo.txt +++ b/tool/allowlists/todo.txt @@ -1,7 +1,5 @@ -numpy.corrcoef numpy.f2py._backends._meson.MesonTemplate.objects_substitution numpy.fft.helper -numpy.lib._function_base_impl.corrcoef numpy.lib._function_base_impl.percentile numpy.lib._index_tricks_impl.AxisConcatenator.concatenate numpy.lib._index_tricks_impl.ndindex.ndincr @@ -119,7 +117,6 @@ numpy.ma.var numpy.ma.vstack numpy.ma.zeros numpy.ma.zeros_like -numpy.matlib.corrcoef numpy.matlib.nanpercentile numpy.matlib.ndindex.ndincr numpy.matlib.percentile From dc3c6fd8b8c7b1989cea6671a7455f8335bce0a8 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 23 Dec 2025 18:40:31 +0100 Subject: [PATCH 04/11] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20`percentile`/`qua?= =?UTF-8?q?ntile`:=20sync=20with=20upstream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../@test/static/accept/lib_function_base.pyi | 50 +- src/numpy-stubs/lib/_function_base_impl.pyi | 503 +++++++++++++++--- tool/allowlists/todo.txt | 3 - 3 files changed, 474 insertions(+), 82 deletions(-) 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/lib/_function_base_impl.pyi b/src/numpy-stubs/lib/_function_base_impl.pyi index bf8a3f8e..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, @@ -74,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] @@ -750,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, @@ -764,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, @@ -790,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, @@ -803,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, @@ -816,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, @@ -829,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, @@ -842,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, @@ -855,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, @@ -881,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, @@ -894,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, *, @@ -907,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, @@ -920,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], diff --git a/tool/allowlists/todo.txt b/tool/allowlists/todo.txt index fffbfd26..8ecf455a 100644 --- a/tool/allowlists/todo.txt +++ b/tool/allowlists/todo.txt @@ -1,6 +1,5 @@ numpy.f2py._backends._meson.MesonTemplate.objects_substitution numpy.fft.helper -numpy.lib._function_base_impl.percentile numpy.lib._index_tricks_impl.AxisConcatenator.concatenate numpy.lib._index_tricks_impl.ndindex.ndincr numpy.lib._nanfunctions_impl.nanpercentile @@ -119,9 +118,7 @@ numpy.ma.zeros numpy.ma.zeros_like numpy.matlib.nanpercentile numpy.matlib.ndindex.ndincr -numpy.matlib.percentile numpy.matlib.save numpy.nanpercentile numpy.ndindex.ndincr -numpy.percentile numpy.save From 62a9347e133ba2e5a18743705259932fef4351ee Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 23 Dec 2025 18:44:36 +0100 Subject: [PATCH 05/11] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20`AxisConcatenator?= =?UTF-8?q?.concatenate`:=20sync=20with=20upstream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/lib/_index_tricks_impl.pyi | 56 ++++++++++++++++++++-- tool/allowlists/todo.txt | 1 - 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/numpy-stubs/lib/_index_tricks_impl.pyi b/src/numpy-stubs/lib/_index_tricks_impl.pyi index aac54d33..2709ebaf 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, @@ -16,8 +16,9 @@ from typing_extensions import TypeVar, deprecated 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_", @@ -139,17 +140,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/tool/allowlists/todo.txt b/tool/allowlists/todo.txt index 8ecf455a..ee25a9f6 100644 --- a/tool/allowlists/todo.txt +++ b/tool/allowlists/todo.txt @@ -1,6 +1,5 @@ numpy.f2py._backends._meson.MesonTemplate.objects_substitution numpy.fft.helper -numpy.lib._index_tricks_impl.AxisConcatenator.concatenate numpy.lib._index_tricks_impl.ndindex.ndincr numpy.lib._nanfunctions_impl.nanpercentile numpy.lib._npyio_impl.save From 4aa20615a88cd327d03eda0f3c3a447ba1bcd4f4 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 23 Dec 2025 18:45:44 +0100 Subject: [PATCH 06/11] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20`ndindex.ndincr`:?= =?UTF-8?q?=20remove?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/lib/_index_tricks_impl.pyi | 4 +--- tool/allowlists/todo.txt | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/numpy-stubs/lib/_index_tricks_impl.pyi b/src/numpy-stubs/lib/_index_tricks_impl.pyi index 2709ebaf..75726ac5 100644 --- a/src/numpy-stubs/lib/_index_tricks_impl.pyi +++ b/src/numpy-stubs/lib/_index_tricks_impl.pyi @@ -12,7 +12,7 @@ from typing import ( final, overload, ) -from typing_extensions import TypeVar, deprecated +from typing_extensions import TypeVar import _numtype as _nt import numpy as np @@ -95,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",) diff --git a/tool/allowlists/todo.txt b/tool/allowlists/todo.txt index ee25a9f6..e77b479b 100644 --- a/tool/allowlists/todo.txt +++ b/tool/allowlists/todo.txt @@ -1,6 +1,5 @@ numpy.f2py._backends._meson.MesonTemplate.objects_substitution numpy.fft.helper -numpy.lib._index_tricks_impl.ndindex.ndincr numpy.lib._nanfunctions_impl.nanpercentile numpy.lib._npyio_impl.save numpy.lib.mixins.NDArrayOperatorsMixin.um @@ -116,8 +115,6 @@ numpy.ma.vstack numpy.ma.zeros numpy.ma.zeros_like numpy.matlib.nanpercentile -numpy.matlib.ndindex.ndincr numpy.matlib.save numpy.nanpercentile -numpy.ndindex.ndincr numpy.save From 8a6c63e4d71e4afb4dde417c2bddda676290afd2 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 23 Dec 2025 18:50:08 +0100 Subject: [PATCH 07/11] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20`lib.=5Fnanfuncti?= =?UTF-8?q?ons=5Fimpl`:=20sync=20with=20upstream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/lib/_nanfunctions_impl.pyi | 278 ++------------------- tool/allowlists/todo.txt | 3 - 2 files changed, 18 insertions(+), 263 deletions(-) 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/tool/allowlists/todo.txt b/tool/allowlists/todo.txt index e77b479b..98edcca2 100644 --- a/tool/allowlists/todo.txt +++ b/tool/allowlists/todo.txt @@ -1,6 +1,5 @@ numpy.f2py._backends._meson.MesonTemplate.objects_substitution numpy.fft.helper -numpy.lib._nanfunctions_impl.nanpercentile numpy.lib._npyio_impl.save numpy.lib.mixins.NDArrayOperatorsMixin.um numpy.linalg.linalg @@ -114,7 +113,5 @@ numpy.ma.var numpy.ma.vstack numpy.ma.zeros numpy.ma.zeros_like -numpy.matlib.nanpercentile numpy.matlib.save -numpy.nanpercentile numpy.save From 48344dcd75505f67f237ae9cbeb7c3e0ee6bae5b Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 23 Dec 2025 18:50:30 +0100 Subject: [PATCH 08/11] =?UTF-8?q?=F0=9F=90=9F=20remove=20unused=20pyright?= =?UTF-8?q?=20ignore=20rules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/@test/static/reject/lib_function_base.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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] From 36d2cbc494b3fd5b063932e7f8d120f2bd14eaf0 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 23 Dec 2025 18:52:34 +0100 Subject: [PATCH 09/11] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20`save`:=20sync=20?= =?UTF-8?q?with=20upstream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/lib/_npyio_impl.pyi | 16 ++-------------- tool/allowlists/todo.txt | 3 --- 2 files changed, 2 insertions(+), 17 deletions(-) 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/tool/allowlists/todo.txt b/tool/allowlists/todo.txt index 98edcca2..63df701c 100644 --- a/tool/allowlists/todo.txt +++ b/tool/allowlists/todo.txt @@ -1,6 +1,5 @@ numpy.f2py._backends._meson.MesonTemplate.objects_substitution numpy.fft.helper -numpy.lib._npyio_impl.save numpy.lib.mixins.NDArrayOperatorsMixin.um numpy.linalg.linalg numpy.ma.all @@ -113,5 +112,3 @@ numpy.ma.var numpy.ma.vstack numpy.ma.zeros numpy.ma.zeros_like -numpy.matlib.save -numpy.save From 0b779534a6fbed7373b052e55a9e03e3477d3f8b Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 23 Dec 2025 18:53:32 +0100 Subject: [PATCH 10/11] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20`NDArrayOperators?= =?UTF-8?q?Mixin`:=20sync=20with=20upstream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/lib/mixins.pyi | 2 -- tool/allowlists/todo.txt | 1 - 2 files changed, 3 deletions(-) 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/tool/allowlists/todo.txt b/tool/allowlists/todo.txt index 63df701c..be55ce32 100644 --- a/tool/allowlists/todo.txt +++ b/tool/allowlists/todo.txt @@ -1,6 +1,5 @@ numpy.f2py._backends._meson.MesonTemplate.objects_substitution numpy.fft.helper -numpy.lib.mixins.NDArrayOperatorsMixin.um numpy.linalg.linalg numpy.ma.all numpy.ma.anom From b5d9eeadeb860ae9e577c73e0e395d9a0b5a2e6f Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 23 Dec 2025 18:57:02 +0100 Subject: [PATCH 11/11] =?UTF-8?q?=F0=9F=90=B4=20update=20mypy=20error=20co?= =?UTF-8?q?de?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/@test/static/reject/npyio.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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]