diff --git a/.mypyignore b/.mypyignore index baafce23..a1f49ff3 100644 --- a/.mypyignore +++ b/.mypyignore @@ -30,6 +30,10 @@ scipy\.(_lib|integrate|stats)\.((_|\w)+\.)+__replace__ # `NamedTuple` on `pytho scipy\.fftpack\.helper\.fftfreq scipy\.sparse\.(\w+)\.warn +# numpy re-export with wrong annotations on numpy<1.24 +scipy.fftpack.fftfreq +scipy.fftpack._helper.fftfreq + # mypy fails recognize type-check-only ufunc subtypes as ufuncs # https://github.com/KotlinIsland/basedmypy/issues/816 scipy\.special\._basic\.digamma diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f534bd69..45d431f6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,6 @@ ci: - typos - ruff - ruff-format - - typetest - basedmypy - basedpyright @@ -74,21 +73,14 @@ repos: - repo: local hooks: - - id: typetest - name: typetest - entry: uv run poe typetest + - id: basedpyright + name: basedpyright + entry: uv run --no-sync basedpyright language: system - always_run: true - pass_filenames: false + types_or: [python, pyi] - id: basedmypy name: basedmypy entry: uv run poe mypy language: system types_or: [python, pyi] - - - id: basedpyright - name: basedpyright - entry: uv run poe pyright - language: system - types_or: [python, pyi] diff --git a/.vscode/settings.json b/.vscode/settings.json index e3da1a2b..311b8b13 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,5 +23,5 @@ "--config-file=${workspaceFolder}/pyproject.toml" ], "mypy-type-checker.cwd": "${fileDirname}", - "mypy-type-checker.path": ["uv", "run", "--no-editable", "mypy"] + "mypy-type-checker.path": ["uv", "run", "--no-sync", "mypy"] } diff --git a/scipy-stubs/_lib/_array_api.pyi b/scipy-stubs/_lib/_array_api.pyi index 78fe5b22..dfa90fd6 100644 --- a/scipy-stubs/_lib/_array_api.pyi +++ b/scipy-stubs/_lib/_array_api.pyi @@ -3,7 +3,6 @@ from typing import Any, Literal, Protocol, TypeAlias, overload, type_check_only from typing_extensions import TypeVar import numpy as np -import numpy.typing as npt import optype.numpy as onp from scipy._typing import AnyBool, OrderKACF @@ -55,7 +54,7 @@ class _HasArrayAttrs(_HasShape[_ShapeT_co], _HasDevice[_DeviceT_co], Protocol[_S ### Array: TypeAlias = _HasArrayAttrs[_ShapeT_co, _DTypeT_co, _DeviceT_co] -ArrayLike: TypeAlias = Array | npt.ArrayLike +ArrayLike: TypeAlias = Array | onp.ToFloatND def _asarray( array: ArrayLike, diff --git a/scipy-stubs/cluster/vq.pyi b/scipy-stubs/cluster/vq.pyi index a50f3de2..a50f96be 100644 --- a/scipy-stubs/cluster/vq.pyi +++ b/scipy-stubs/cluster/vq.pyi @@ -2,7 +2,6 @@ from typing import Any, Literal, overload from typing_extensions import TypeVar import numpy as np -import numpy.typing as npt import optype.numpy as onp from scipy._typing import Seed @@ -27,6 +26,8 @@ def vq( code_book: onp.ToComplex2D, check_finite: bool = True, ) -> tuple[onp.Array1D[np.int32 | np.intp], onp.Array1D[_SCT_fc]]: ... + +# def py_vq( obs: onp.ToComplex2D, code_book: onp.ToComplex2D, @@ -34,18 +35,44 @@ def py_vq( ) -> tuple[onp.Array1D[np.intp], onp.Array1D[_SCT_fc]]: ... # +@overload # real +def kmeans( + obs: onp.ToFloat2D, + k_or_guess: onp.ToJustInt | onp.ToFloatND, + iter: int = 20, + thresh: float = 1e-05, + check_finite: bool = True, + *, + seed: Seed | None = None, +) -> tuple[onp.Array2D[np.floating[Any]], float]: ... +@overload # complex def kmeans( obs: onp.ToComplex2D, - k_or_guess: npt.ArrayLike, + k_or_guess: onp.ToJustInt | onp.ToFloatND, iter: int = 20, thresh: float = 1e-05, check_finite: bool = True, *, seed: Seed | None = None, ) -> tuple[onp.Array2D[np.inexact[Any]], float]: ... + +# +@overload # real +def kmeans2( + data: onp.ToFloat1D | onp.ToFloat2D, + k: onp.ToJustInt | onp.ToFloatND, + iter: int = 10, + thresh: float = 1e-05, + minit: Literal["random", "points", "++", "matrix"] = "random", + missing: Literal["warn", "raise"] = "warn", + check_finite: bool = True, + *, + seed: Seed | None = None, +) -> tuple[onp.Array2D[np.floating[Any]], onp.Array1D[np.int32]]: ... +@overload # complex def kmeans2( data: onp.ToComplex1D | onp.ToComplex2D, - k: npt.ArrayLike, + k: onp.ToJustInt | onp.ToFloatND, iter: int = 10, thresh: float = 1e-05, minit: Literal["random", "points", "++", "matrix"] = "random", diff --git a/scipy-stubs/fftpack/_helper.pyi b/scipy-stubs/fftpack/_helper.pyi index b75e140c..6c5952a6 100644 --- a/scipy-stubs/fftpack/_helper.pyi +++ b/scipy-stubs/fftpack/_helper.pyi @@ -1,3 +1,6 @@ +# NOTE: this ignore is required for `numpy==1.23.5` compat +# pyright: reportUnknownVariableType=false + import numpy as np import optype.numpy as onp from numpy.fft import fftfreq, fftshift, ifftshift diff --git a/scipy-stubs/interpolate/_pade.pyi b/scipy-stubs/interpolate/_pade.pyi index 23cb7877..46d1322a 100644 --- a/scipy-stubs/interpolate/_pade.pyi +++ b/scipy-stubs/interpolate/_pade.pyi @@ -1,6 +1,6 @@ import numpy as np -import numpy.typing as npt +import optype.numpy as onp __all__ = ["pade"] -def pade(an: npt.ArrayLike, m: int, n: int | None = None) -> tuple[np.poly1d, np.poly1d]: ... +def pade(an: onp.ToComplex1D, m: onp.ToJustInt, n: onp.ToJustInt | None = None) -> tuple[np.poly1d, np.poly1d]: ... diff --git a/scipy-stubs/io/_fortran.pyi b/scipy-stubs/io/_fortran.pyi index 91ae162e..53bb1a0f 100644 --- a/scipy-stubs/io/_fortran.pyi +++ b/scipy-stubs/io/_fortran.pyi @@ -8,9 +8,9 @@ from scipy._typing import EnterSelfMixin, FileLike, FileModeRW __all__ = ["FortranEOFError", "FortranFile", "FortranFormattingError"] -@type_check_only @final -class _DTypeKwargs(TypedDict): +@type_check_only +class _DTypeKwargs(TypedDict, total=False): dtype: npt.DTypeLike class FortranEOFError(TypeError, OSError): ... @@ -19,7 +19,7 @@ class FortranFormattingError(TypeError, OSError): ... class FortranFile(EnterSelfMixin): def __init__(self, /, filename: FileLike[bytes], mode: FileModeRW = "r", header_dtype: npt.DTypeLike = ...) -> None: ... def close(self, /) -> None: ... - def write_record(self, /, *items: npt.ArrayLike) -> None: ... + def write_record(self, /, *items: onp.ToArrayND) -> None: ... @overload def read_record(self, /, *dtypes: npt.DTypeLike) -> onp.Array1D[np.void]: ... @overload diff --git a/scipy-stubs/io/_mmio.pyi b/scipy-stubs/io/_mmio.pyi index 129d0ce3..17bbfee1 100644 --- a/scipy-stubs/io/_mmio.pyi +++ b/scipy-stubs/io/_mmio.pyi @@ -2,7 +2,6 @@ from typing import Any, ClassVar, Literal, TypeAlias, TypedDict, type_check_only from typing_extensions import Unpack import numpy as np -import numpy.typing as npt import optype.numpy as onp from scipy._typing import FileLike from scipy.sparse import coo_matrix, sparray, spmatrix @@ -28,7 +27,7 @@ def mminfo(source: FileLike[bytes]) -> _Info: ... def mmread(source: FileLike[bytes]) -> onp.ArrayND[np.number[Any]] | coo_matrix: ... def mmwrite( target: FileLike[bytes], - a: spmatrix | sparray | npt.ArrayLike, + a: spmatrix | sparray | onp.ToArrayND, comment: str = "", field: _Field | None = None, precision: int | None = None, @@ -75,7 +74,7 @@ class MMFile: self, /, target: FileLike[bytes], - a: spmatrix | sparray | npt.ArrayLike, + a: spmatrix | sparray | onp.ToArrayND, comment: str = "", field: _Field | None = None, precision: int | None = None, diff --git a/scipy-stubs/io/matlab/_mio4.pyi b/scipy-stubs/io/matlab/_mio4.pyi index 52b7ce8d..735e4807 100644 --- a/scipy-stubs/io/matlab/_mio4.pyi +++ b/scipy-stubs/io/matlab/_mio4.pyi @@ -3,7 +3,6 @@ from typing import IO, Any, Final, Generic, Literal, Protocol, TypeAlias, type_c from typing_extensions import LiteralString, TypeVar import numpy as np -import numpy.typing as npt import optype.numpy as onp from scipy.sparse import coo_matrix, sparray, spmatrix from ._miobase import MatFileReader @@ -119,7 +118,7 @@ class VarWriter4: def write_bytes(self, /, arr: onp.ArrayND) -> None: ... def write_string(self, /, s: str) -> None: ... def write_header(self, /, name: str, shape: Sequence[int], P: _MDType = 0, T: _MClass = 0, imagf: int = 0) -> None: ... - def write(self, /, arr: npt.ArrayLike, name: str) -> None: ... + def write(self, /, arr: onp.ToArrayND, name: str) -> None: ... def write_numeric(self, /, arr: onp.ArrayND[np.number[Any]], name: str) -> None: ... def write_char(self, /, arr: onp.ArrayND[np.character], name: str) -> None: ... def write_sparse(self, /, arr: spmatrix | sparray, name: str) -> None: ... diff --git a/scipy-stubs/io/matlab/_mio5.pyi b/scipy-stubs/io/matlab/_mio5.pyi index 6daa3447..ad10b5b4 100644 --- a/scipy-stubs/io/matlab/_mio5.pyi +++ b/scipy-stubs/io/matlab/_mio5.pyi @@ -3,7 +3,6 @@ from collections.abc import Iterable, Mapping from typing import IO, Any, Final, Literal, TypeAlias, TypedDict, final, type_check_only import numpy as np -import numpy.typing as npt import optype.numpy as onp from scipy._typing import AnyShape, ByteOrder from scipy.sparse import sparray, spmatrix @@ -75,8 +74,8 @@ class VarWriter5: nzmax: int = 0, ) -> None: ... def update_matrix_tag(self, /, start_pos: int) -> None: ... - def write_top(self, /, arr: npt.ArrayLike, name: str, is_global: bool) -> None: ... - def write(self, /, arr: npt.ArrayLike) -> None: ... + def write_top(self, /, arr: onp.ToArrayND, name: str, is_global: bool) -> None: ... + def write(self, /, arr: onp.ToArrayND) -> None: ... def write_numeric(self, /, arr: onp.ArrayND[np.bool_ | np.number[Any]]) -> None: ... def write_char(self, /, arr: onp.ArrayND[np.str_], codec: str = "ascii") -> None: ... def write_sparse(self, /, arr: spmatrix | sparray) -> None: ... diff --git a/scipy-stubs/linalg/_misc.pyi b/scipy-stubs/linalg/_misc.pyi index f1355345..ae28c630 100644 --- a/scipy-stubs/linalg/_misc.pyi +++ b/scipy-stubs/linalg/_misc.pyi @@ -51,7 +51,7 @@ def norm( ) -> np.float64: ... @overload # float64-coercible array, keepdims: True (positional) def norm( - a: onp.CanArrayND[_SubScalar, _ShapeT], + a: onp.ArrayND[_SubScalar, _ShapeT], ord: _Order | None, axis: _Axis | None, keepdims: _Truthy, @@ -59,7 +59,7 @@ def norm( ) -> onp.ArrayND[np.float64, _ShapeT]: ... @overload # float64-coercible array, keepdims: True (keyword) def norm( - a: onp.CanArrayND[_SubScalar, _ShapeT], + a: onp.ArrayND[_SubScalar, _ShapeT], ord: _Order | None = None, axis: _Axis | None = None, *, @@ -85,7 +85,7 @@ def norm( ) -> onp.ArrayND[np.float64]: ... @overload # shaped inexact array, keepdims: True (positional) def norm( - a: onp.CanArrayND[np.inexact[_NBitT], _ShapeT], + a: onp.ArrayND[np.inexact[_NBitT], _ShapeT], ord: _Order | None, axis: _Axis | None, keepdims: _Truthy, @@ -93,7 +93,7 @@ def norm( ) -> onp.ArrayND[np.floating[_NBitT], _ShapeT]: ... @overload # shaped inexact array, keepdims: True (keyword) def norm( - a: onp.CanArrayND[np.inexact[_NBitT], _ShapeT], + a: onp.ArrayND[np.inexact[_NBitT], _ShapeT], ord: _Order | None = None, axis: _Axis | None = None, *, @@ -144,7 +144,7 @@ def norm( ) -> onp.ArrayND[np.floating[Any]]: ... @overload # catch-all def norm( - a: npt.ArrayLike, + a: onp.ToArrayND, ord: _Order | None = None, axis: _Axis | None = None, keepdims: AnyBool = False, diff --git a/scipy-stubs/ndimage/_interpolation.pyi b/scipy-stubs/ndimage/_interpolation.pyi index 1d28bf76..663973e4 100644 --- a/scipy-stubs/ndimage/_interpolation.pyi +++ b/scipy-stubs/ndimage/_interpolation.pyi @@ -2,7 +2,6 @@ from collections.abc import Callable from typing import Concatenate, Literal, TypeAlias, TypeVar, overload import numpy as np -import numpy.typing as npt import optype.numpy as onp from ._typing import _ComplexArrayOut, _FloatArrayOut @@ -25,7 +24,7 @@ _MappingFunc: TypeAlias = Callable[Concatenate[tuple[int, ...], ...], tuple[onp. # @overload def spline_filter1d( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, order: _Order = 3, axis: onp.ToInt = -1, output: type[float | np.float64] = ..., @@ -33,7 +32,7 @@ def spline_filter1d( ) -> onp.ArrayND[np.float64]: ... @overload def spline_filter1d( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, order: _Order = 3, axis: onp.ToInt = -1, output: type[complex] = ..., @@ -41,7 +40,7 @@ def spline_filter1d( ) -> onp.ArrayND[np.complex128 | np.float64]: ... @overload def spline_filter1d( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, order: _Order, axis: onp.ToInt, output: onp.ArrayND[_SCT] | type[_SCT], @@ -49,7 +48,7 @@ def spline_filter1d( ) -> onp.ArrayND[_SCT]: ... @overload def spline_filter1d( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, order: _Order = 3, axis: onp.ToInt = -1, *, @@ -60,28 +59,28 @@ def spline_filter1d( # @overload def spline_filter( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, order: _Order = 3, output: type[float | np.float64] = ..., mode: _Mode = "mirror", ) -> onp.ArrayND[np.float64]: ... @overload def spline_filter( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, order: _Order = 3, output: type[complex] = ..., mode: _Mode = "mirror", ) -> onp.ArrayND[np.complex128 | np.float64]: ... @overload def spline_filter( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, order: _Order, output: onp.ArrayND[_SCT] | type[_SCT], mode: _Mode = "mirror", ) -> onp.ArrayND[_SCT]: ... @overload def spline_filter( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, order: _Order = 3, *, output: onp.ArrayND[_SCT] | type[_SCT], @@ -117,7 +116,7 @@ def geometric_transform( ) -> _ComplexArrayOut: ... @overload def geometric_transform( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, mapping: _MappingFunc, output_shape: tuple[int, ...] | None, output: onp.ArrayND[_SCT] | type[_SCT], @@ -130,7 +129,7 @@ def geometric_transform( ) -> onp.ArrayND[_SCT]: ... @overload def geometric_transform( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, mapping: _MappingFunc, output_shape: tuple[int, ...] | None = None, *, @@ -144,7 +143,7 @@ def geometric_transform( ) -> onp.ArrayND[_SCT]: ... @overload def geometric_transform( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, mapping: _MappingFunc, output_shape: tuple[int, ...] | None = None, *, @@ -158,7 +157,7 @@ def geometric_transform( ) -> onp.ArrayND[np.int_]: ... @overload def geometric_transform( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, mapping: _MappingFunc, output_shape: tuple[int, ...] | None = None, *, @@ -172,7 +171,7 @@ def geometric_transform( ) -> onp.ArrayND[np.float64 | np.int_]: ... @overload def geometric_transform( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, mapping: _MappingFunc, output_shape: tuple[int, ...] | None = None, *, @@ -208,7 +207,7 @@ def map_coordinates( ) -> _ComplexArrayOut: ... @overload def map_coordinates( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, coordinates: onp.ToFloat | onp.ToFloatND, output: onp.ArrayND[_SCT] | type[_SCT], order: _Order = 3, @@ -218,7 +217,7 @@ def map_coordinates( ) -> onp.ArrayND[_SCT]: ... @overload def map_coordinates( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, coordinates: onp.ToFloat | onp.ToFloatND, output: type[bool], order: _Order = 3, @@ -228,7 +227,7 @@ def map_coordinates( ) -> onp.ArrayND[np.bool_]: ... @overload def map_coordinates( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, coordinates: onp.ToFloat | onp.ToFloatND, output: type[int], order: _Order = 3, @@ -238,7 +237,7 @@ def map_coordinates( ) -> onp.ArrayND[np.int_ | np.bool_]: ... @overload def map_coordinates( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, coordinates: onp.ToFloat | onp.ToFloatND, output: type[float], order: _Order = 3, @@ -248,7 +247,7 @@ def map_coordinates( ) -> onp.ArrayND[np.float64 | np.int_ | np.bool_]: ... @overload def map_coordinates( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, coordinates: onp.ToFloat | onp.ToFloatND, output: type[complex], order: _Order = 3, @@ -284,7 +283,7 @@ def affine_transform( ) -> _ComplexArrayOut: ... @overload def affine_transform( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, matrix: onp.ToFloat | onp.ToFloat1D | onp.ToFloat2D, offset: onp.ToFloat | onp.ToFloat1D = 0.0, output_shape: tuple[int, ...] | None = None, @@ -297,7 +296,7 @@ def affine_transform( ) -> onp.ArrayND[_SCT]: ... @overload def affine_transform( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, matrix: onp.ToFloat | onp.ToFloat1D | onp.ToFloat2D, offset: onp.ToFloat | onp.ToFloat1D = 0.0, output_shape: tuple[int, ...] | None = None, @@ -310,7 +309,7 @@ def affine_transform( ) -> onp.ArrayND[np.int_]: ... @overload def affine_transform( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, matrix: onp.ToFloat | onp.ToFloat1D | onp.ToFloat2D, offset: onp.ToFloat | onp.ToFloat1D = 0.0, output_shape: tuple[int, ...] | None = None, @@ -323,7 +322,7 @@ def affine_transform( ) -> onp.ArrayND[np.float64 | np.int_]: ... @overload def affine_transform( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, matrix: onp.ToFloat | onp.ToFloat1D | onp.ToFloat2D, offset: onp.ToFloat | onp.ToFloat1D = 0.0, output_shape: tuple[int, ...] | None = None, @@ -358,7 +357,7 @@ def shift( ) -> _ComplexArrayOut: ... @overload def shift( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, shift: onp.ToFloat | onp.ToFloatND, output: onp.ArrayND[_SCT] | type[_SCT], order: _Order = 3, @@ -368,7 +367,7 @@ def shift( ) -> onp.ArrayND[_SCT]: ... @overload def shift( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, shift: onp.ToFloat | onp.ToFloatND, output: type[int], order: _Order = 3, @@ -378,7 +377,7 @@ def shift( ) -> onp.ArrayND[np.int_]: ... @overload def shift( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, shift: onp.ToFloat | onp.ToFloatND, output: type[float], order: _Order = 3, @@ -388,7 +387,7 @@ def shift( ) -> onp.ArrayND[np.float64 | np.int_]: ... @overload def shift( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, shift: onp.ToFloat | onp.ToFloatND, output: type[complex], order: _Order = 3, @@ -424,7 +423,7 @@ def zoom( ) -> _ComplexArrayOut: ... @overload def zoom( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, zoom: onp.ToFloat | onp.ToFloatND, output: onp.ArrayND[_SCT] | type[_SCT], order: _Order = 3, @@ -436,7 +435,7 @@ def zoom( ) -> onp.ArrayND[_SCT]: ... @overload def zoom( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, zoom: onp.ToFloat | onp.ToFloatND, output: type[int], order: _Order = 3, @@ -448,7 +447,7 @@ def zoom( ) -> onp.ArrayND[np.int_]: ... @overload def zoom( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, zoom: onp.ToFloat | onp.ToFloatND, output: type[float], order: _Order = 3, @@ -460,7 +459,7 @@ def zoom( ) -> onp.ArrayND[np.float64 | np.int_]: ... @overload def zoom( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, zoom: onp.ToFloat | onp.ToFloatND, output: type[complex], order: _Order = 3, @@ -498,7 +497,7 @@ def rotate( ) -> _ComplexArrayOut: ... @overload def rotate( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, angle: onp.ToFloat, axes: tuple[onp.ToInt, onp.ToInt] = (1, 0), reshape: bool = True, @@ -511,7 +510,7 @@ def rotate( ) -> onp.ArrayND[_SCT]: ... @overload def rotate( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, angle: onp.ToFloat, axes: tuple[onp.ToInt, onp.ToInt] = (1, 0), reshape: bool = True, @@ -524,7 +523,7 @@ def rotate( ) -> onp.ArrayND[np.int_]: ... @overload def rotate( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, angle: onp.ToFloat, axes: tuple[onp.ToInt, onp.ToInt] = (1, 0), reshape: bool = True, @@ -537,7 +536,7 @@ def rotate( ) -> onp.ArrayND[np.float64 | np.int_]: ... @overload def rotate( - input: npt.ArrayLike, + input: onp.ToScalar | onp.ToArrayND, angle: onp.ToFloat, axes: tuple[onp.ToInt, onp.ToInt] = (1, 0), reshape: bool = True, diff --git a/scipy-stubs/ndimage/_morphology.pyi b/scipy-stubs/ndimage/_morphology.pyi index 6e401ad5..0f4b227b 100644 --- a/scipy-stubs/ndimage/_morphology.pyi +++ b/scipy-stubs/ndimage/_morphology.pyi @@ -1,7 +1,6 @@ from typing import Literal, TypeAlias import numpy as np -import numpy.typing as npt import optype.numpy as onp from ._typing import _ScalarArrayOut @@ -107,7 +106,7 @@ def binary_fill_holes( def grey_erosion( input: onp.ToComplex | onp.ToComplexND, size: tuple[int, ...] | None = None, - footprint: npt.ArrayLike | None = None, + footprint: onp.ToScalar | onp.ToArrayND | None = None, structure: onp.ToInt | onp.ToIntND | None = None, output: _ScalarArrayOut | None = None, mode: _Mode = "reflect", @@ -117,7 +116,7 @@ def grey_erosion( def grey_dilation( input: onp.ToComplex | onp.ToComplexND, size: tuple[int, ...] | None = None, - footprint: npt.ArrayLike | None = None, + footprint: onp.ToScalar | onp.ToArrayND | None = None, structure: onp.ToInt | onp.ToIntND | None = None, output: _ScalarArrayOut | None = None, mode: _Mode = "reflect", @@ -127,7 +126,7 @@ def grey_dilation( def grey_opening( input: onp.ToComplex | onp.ToComplexND, size: tuple[int, ...] | None = None, - footprint: npt.ArrayLike | None = None, + footprint: onp.ToScalar | onp.ToArrayND | None = None, structure: onp.ToInt | onp.ToIntND | None = None, output: _ScalarArrayOut | None = None, mode: _Mode = "reflect", @@ -137,7 +136,7 @@ def grey_opening( def grey_closing( input: onp.ToComplex | onp.ToComplexND, size: tuple[int, ...] | None = None, - footprint: npt.ArrayLike | None = None, + footprint: onp.ToScalar | onp.ToArrayND | None = None, structure: onp.ToInt | onp.ToIntND | None = None, output: _ScalarArrayOut | None = None, mode: _Mode = "reflect", @@ -147,7 +146,7 @@ def grey_closing( def morphological_gradient( input: onp.ToComplex | onp.ToComplexND, size: tuple[int, ...] | None = None, - footprint: npt.ArrayLike | None = None, + footprint: onp.ToScalar | onp.ToArrayND | None = None, structure: onp.ToInt | onp.ToIntND | None = None, output: _ScalarArrayOut | None = None, mode: _Mode = "reflect", @@ -157,7 +156,7 @@ def morphological_gradient( def morphological_laplace( input: onp.ToComplex | onp.ToComplexND, size: tuple[int, ...] | None = None, - footprint: npt.ArrayLike | None = None, + footprint: onp.ToScalar | onp.ToArrayND | None = None, structure: onp.ToInt | onp.ToIntND | None = None, output: _ScalarArrayOut | None = None, mode: _Mode = "reflect", @@ -167,7 +166,7 @@ def morphological_laplace( def white_tophat( input: onp.ToComplex | onp.ToComplexND, size: tuple[int, ...] | None = None, - footprint: npt.ArrayLike | None = None, + footprint: onp.ToScalar | onp.ToArrayND | None = None, structure: onp.ToInt | onp.ToIntND | None = None, output: _ScalarArrayOut | None = None, mode: _Mode = "reflect", @@ -177,7 +176,7 @@ def white_tophat( def black_tophat( input: onp.ToComplex | onp.ToComplexND, size: tuple[int, ...] | None = None, - footprint: npt.ArrayLike | None = None, + footprint: onp.ToScalar | onp.ToArrayND | None = None, structure: onp.ToInt | onp.ToIntND | None = None, output: _ScalarArrayOut | None = None, mode: _Mode = "reflect", @@ -195,7 +194,7 @@ def distance_transform_bf( ) -> _ScalarArrayOut | onp.ArrayND[np.int32] | tuple[_ScalarArrayOut, onp.ArrayND[np.int32]]: ... def distance_transform_cdt( input: onp.ToComplex | onp.ToComplexND, - metric: _MetricCDT | npt.ArrayLike = "chessboard", + metric: _MetricCDT | onp.ToScalar | onp.ToArrayND = "chessboard", return_distances: onp.ToBool = True, return_indices: onp.ToBool = False, distances: onp.ArrayND[np.int32] | None = None, @@ -203,7 +202,7 @@ def distance_transform_cdt( ) -> onp.ArrayND[np.int32] | tuple[onp.ArrayND[np.int32], onp.ArrayND[np.int32]]: ... def distance_transform_edt( input: onp.ToComplex | onp.ToComplexND, - sampling: npt.ArrayLike | None = None, + sampling: onp.ToScalar | onp.ToArrayND | None = None, return_distances: onp.ToBool = True, return_indices: onp.ToBool = False, distances: onp.ArrayND[np.float64] | None = None, diff --git a/scipy-stubs/optimize/_linprog.pyi b/scipy-stubs/optimize/_linprog.pyi index 45b8227a..a29c1b18 100644 --- a/scipy-stubs/optimize/_linprog.pyi +++ b/scipy-stubs/optimize/_linprog.pyi @@ -2,7 +2,6 @@ from collections.abc import Callable, Mapping, Sequence from typing import Final, Literal, type_check_only import numpy as np -import numpy.typing as npt import optype.numpy as onp from ._optimize import OptimizeResult from ._typing import Bound, MethodLinprog @@ -28,16 +27,16 @@ def linprog_terse_callback(res: _OptimizeResult) -> None: ... # TODO: Tighen these array-like types def linprog( - c: npt.ArrayLike, - A_ub: npt.ArrayLike | None = None, - b_ub: npt.ArrayLike | None = None, - A_eq: npt.ArrayLike | None = None, - b_eq: npt.ArrayLike | None = None, + c: onp.ToScalar | onp.ToArrayND, + A_ub: onp.ToScalar | onp.ToArrayND | None = None, + b_ub: onp.ToScalar | onp.ToArrayND | None = None, + A_eq: onp.ToScalar | onp.ToArrayND | None = None, + b_eq: onp.ToScalar | onp.ToArrayND | None = None, bounds: Bound = (0, None), method: MethodLinprog = "highs", callback: Callable[[_OptimizeResult], None] | None = None, # TODO: `TypedDict` options: Mapping[str, object] | None = None, - x0: npt.ArrayLike | None = None, - integrality: npt.ArrayLike | None = None, + x0: onp.ToScalar | onp.ToArrayND | None = None, + integrality: onp.ToScalar | onp.ToArrayND | None = None, ) -> _OptimizeResult: ... diff --git a/scipy-stubs/optimize/_nnls.pyi b/scipy-stubs/optimize/_nnls.pyi index 42de0b14..d65eb4cb 100644 --- a/scipy-stubs/optimize/_nnls.pyi +++ b/scipy-stubs/optimize/_nnls.pyi @@ -1,12 +1,11 @@ import numpy as np -import numpy.typing as npt import optype.numpy as onp __all__ = ["nnls"] def nnls( - A: npt.ArrayLike, - b: npt.ArrayLike, + A: onp.ToFloat2D, + b: onp.ToFloat2D, maxiter: onp.ToInt | None = None, *, atol: onp.ToFloat | None = None, diff --git a/scipy-stubs/optimize/_tnc.pyi b/scipy-stubs/optimize/_tnc.pyi index 0c0961e1..12ca4403 100644 --- a/scipy-stubs/optimize/_tnc.pyi +++ b/scipy-stubs/optimize/_tnc.pyi @@ -1,8 +1,7 @@ from collections.abc import Callable, Sequence -from typing import Any, Final, Literal, TypeAlias +from typing import Final, Literal, TypeAlias import numpy as np -import numpy.typing as npt import optype.numpy as onp __all__ = ["fmin_tnc"] @@ -29,15 +28,15 @@ USERABORT: Final = 7 RCSTRINGS: Final[dict[_ReturnCode, str]] def fmin_tnc( - func: Callable[..., float | np.floating[Any]] | Callable[..., tuple[float | np.floating[Any], float | np.floating[Any]]], - x0: npt.ArrayLike, - fprime: Callable[..., float | np.floating[Any]] | None = None, + func: Callable[..., onp.ToFloat] | Callable[..., tuple[onp.ToFloat, onp.ToFloat]], + x0: onp.ToFloat | onp.ToFloat1D, + fprime: Callable[..., onp.ToFloat] | None = None, args: tuple[object, ...] = (), approx_grad: int = 0, bounds: Sequence[tuple[float | None, float | None]] | None = None, epsilon: float = 1e-08, - scale: npt.ArrayLike | None = None, - offset: npt.ArrayLike | None = None, + scale: onp.ToFloat | onp.ToFloat1D | None = None, + offset: onp.ToFloat | onp.ToFloat1D | None = None, messages: int = ..., maxCGit: int = -1, maxfun: int | None = None, @@ -50,5 +49,5 @@ def fmin_tnc( pgtol: float = -1, rescale: float = -1, disp: bool | None = None, - callback: Callable[[onp.ArrayND[np.floating[Any]]], None] | None = None, -) -> tuple[onp.ArrayND[np.floating[Any]], int, _ReturnCode]: ... + callback: Callable[[onp.Array1D[np.float64]], None] | None = None, +) -> tuple[onp.Array1D[np.float64], int, _ReturnCode]: ... diff --git a/scipy-stubs/signal/_savitzky_golay.pyi b/scipy-stubs/signal/_savitzky_golay.pyi index 672962fc..1f730597 100644 --- a/scipy-stubs/signal/_savitzky_golay.pyi +++ b/scipy-stubs/signal/_savitzky_golay.pyi @@ -1,7 +1,6 @@ from typing import Any, Literal, TypeAlias import numpy as np -import numpy.typing as npt import optype as op import optype.numpy as onp @@ -15,8 +14,10 @@ def savgol_coeffs( pos: int | None = None, use: Literal["conv", "dot"] = "conv", ) -> onp.Array1D[np.floating[Any]]: ... + +# def savgol_filter( - x: npt.ArrayLike, + x: onp.ToFloatND, window_length: int, polyorder: int, deriv: int = 0, diff --git a/scipy-stubs/signal/_signaltools.pyi b/scipy-stubs/signal/_signaltools.pyi index c6efb73b..8205823b 100644 --- a/scipy-stubs/signal/_signaltools.pyi +++ b/scipy-stubs/signal/_signaltools.pyi @@ -1,7 +1,7 @@ from typing import Literal from typing_extensions import deprecated -import numpy.typing as npt +import optype.numpy as onp from scipy._typing import Untyped, UntypedArray __all__ = [ @@ -84,7 +84,7 @@ def detrend( data: UntypedArray, axis: int = -1, type: Literal["linear", "constant"] = "linear", - bp: npt.ArrayLike | int = 0, + bp: onp.ToJustInt | onp.ToJustIntND = 0, overwrite_data: bool = False, ) -> UntypedArray: ... def lfilter_zi(b: Untyped, a: Untyped) -> Untyped: ... diff --git a/scipy-stubs/sparse/csgraph/_laplacian.pyi b/scipy-stubs/sparse/csgraph/_laplacian.pyi index 28a7fe06..14f2de90 100644 --- a/scipy-stubs/sparse/csgraph/_laplacian.pyi +++ b/scipy-stubs/sparse/csgraph/_laplacian.pyi @@ -8,10 +8,11 @@ from scipy.sparse.linalg import LinearOperator _LaplacianMatrix: TypeAlias = onp.Array2D[np.number[Any]] | sparray | spmatrix | LinearOperator _LaplacianDiag: TypeAlias = onp.Array1D[np.number[Any]] +_ToCSGraph: TypeAlias = onp.ToComplex2D | sparray | spmatrix @overload def laplacian( - csgraph: npt.ArrayLike | spmatrix | sparray, + csgraph: _ToCSGraph, normed: bool = False, return_diag: Literal[False] = False, use_out_degree: bool = False, @@ -23,7 +24,7 @@ def laplacian( ) -> _LaplacianMatrix: ... @overload def laplacian( - csgraph: npt.ArrayLike | spmatrix | sparray, + csgraph: _ToCSGraph, normed: bool, return_diag: Literal[True], use_out_degree: bool = False, @@ -35,7 +36,7 @@ def laplacian( ) -> tuple[_LaplacianMatrix, _LaplacianDiag]: ... @overload def laplacian( - csgraph: npt.ArrayLike | spmatrix | sparray, + csgraph: _ToCSGraph, normed: bool = False, *, return_diag: Literal[True], diff --git a/scipy-stubs/sparse/csgraph/_min_spanning_tree.pyi b/scipy-stubs/sparse/csgraph/_min_spanning_tree.pyi index 172c5fbd..d5e39263 100644 --- a/scipy-stubs/sparse/csgraph/_min_spanning_tree.pyi +++ b/scipy-stubs/sparse/csgraph/_min_spanning_tree.pyi @@ -1,10 +1,10 @@ from typing import Final import numpy as np -import numpy.typing as npt +import optype.numpy as onp from scipy.sparse import csr_matrix, sparray, spmatrix DTYPE: Final[type[np.float64]] = ... ITYPE: Final[type[np.int32]] = ... -def minimum_spanning_tree(csgraph: spmatrix | sparray | npt.ArrayLike, overwrite: bool = False) -> csr_matrix: ... +def minimum_spanning_tree(csgraph: onp.ToFloat2D | spmatrix | sparray, overwrite: bool = False) -> csr_matrix: ... diff --git a/scipy-stubs/sparse/linalg/_interface.pyi b/scipy-stubs/sparse/linalg/_interface.pyi index 36be9297..615e056a 100644 --- a/scipy-stubs/sparse/linalg/_interface.pyi +++ b/scipy-stubs/sparse/linalg/_interface.pyi @@ -1,7 +1,7 @@ # pyright: reportInconsistentConstructor=false from collections.abc import Sequence -from typing import ClassVar, Literal +from typing import ClassVar, Literal, TypeAlias from typing_extensions import Self, override import numpy as np @@ -11,6 +11,10 @@ from scipy._typing import Untyped, UntypedArray, UntypedTuple __all__ = ["LinearOperator", "aslinearoperator"] +_ToLinearOperator: TypeAlias = LinearOperator | onp.ToComplex1D | onp.ToComplex2D + +### + # TODO: make these all generic class LinearOperator: __array_ufunc__: ClassVar[None] @@ -21,25 +25,17 @@ class LinearOperator: def __new__(cls, *args: Untyped, **kwargs: Untyped) -> Self: ... def __init__(self, /, dtype: npt.DTypeLike, shape: onp.ToInt | Sequence[onp.ToInt]) -> None: ... - def matvec(self, /, x: npt.ArrayLike) -> UntypedArray: ... - def rmatvec(self, /, x: npt.ArrayLike) -> UntypedArray: ... - def matmat(self, /, X: npt.ArrayLike) -> UntypedArray: ... - def rmatmat(self, /, X: npt.ArrayLike) -> UntypedArray: ... - def __call__(self, /, x: npt.ArrayLike | LinearOperator) -> _ProductLinearOperator | _ScaledLinearOperator | UntypedArray: ... - def __mul__(self, x: LinearOperator | npt.ArrayLike, /) -> _ProductLinearOperator | _ScaledLinearOperator | UntypedArray: ... + def matvec(self, /, x: onp.ToComplex1D | onp.ToComplex2D) -> UntypedArray: ... + def rmatvec(self, /, x: onp.ToComplex1D | onp.ToComplex2D) -> UntypedArray: ... + def matmat(self, /, X: onp.ToComplex2D) -> UntypedArray: ... + def rmatmat(self, /, X: onp.ToComplex2D) -> UntypedArray: ... + def __call__(self, /, x: _ToLinearOperator) -> _ProductLinearOperator | _ScaledLinearOperator | UntypedArray: ... + def __mul__(self, x: _ToLinearOperator, /) -> _ProductLinearOperator | _ScaledLinearOperator | UntypedArray: ... def __truediv__(self, other: onp.ToScalar, /) -> _ScaledLinearOperator: ... - def dot(self, /, x: LinearOperator | npt.ArrayLike) -> _ProductLinearOperator | _ScaledLinearOperator | UntypedArray: ... - def __matmul__( - self, - other: LinearOperator | onp.CanArray[tuple[int, ...], np.dtype[np.generic]], - /, - ) -> _ScaledLinearOperator | UntypedArray: ... - def __rmatmul__( - self, - other: LinearOperator | onp.CanArray[tuple[int, ...], np.dtype[np.generic]], - /, - ) -> _ScaledLinearOperator | UntypedArray: ... - def __rmul__(self, x: LinearOperator | npt.ArrayLike, /) -> Untyped: ... + def dot(self, /, x: _ToLinearOperator) -> _ProductLinearOperator | _ScaledLinearOperator | UntypedArray: ... + def __matmul__(self, other: _ToLinearOperator, /) -> _ScaledLinearOperator | UntypedArray: ... + def __rmatmul__(self, other: _ToLinearOperator, /) -> _ScaledLinearOperator | UntypedArray: ... + def __rmul__(self, x: _ToLinearOperator, /) -> Untyped: ... def __pow__(self, p: onp.ToScalar, /) -> _PowerLinearOperator: ... def __add__(self, x: LinearOperator, /) -> _SumLinearOperator: ... def __neg__(self, /) -> _ScaledLinearOperator: ... diff --git a/scipy-stubs/sparse/linalg/_svdp.pyi b/scipy-stubs/sparse/linalg/_svdp.pyi index 7834f077..79d069a7 100644 --- a/scipy-stubs/sparse/linalg/_svdp.pyi +++ b/scipy-stubs/sparse/linalg/_svdp.pyi @@ -1,6 +1,6 @@ from typing import Literal -import numpy.typing as npt +import optype.numpy as onp from scipy._typing import Seed, UntypedArray from scipy.sparse import sparray, spmatrix from ._interface import LinearOperator @@ -8,14 +8,14 @@ from ._interface import LinearOperator __all__ = ["_svdp"] def _svdp( - A: npt.ArrayLike | sparray | spmatrix | LinearOperator, + A: onp.ToComplex2D | sparray | spmatrix | LinearOperator, k: int, which: Literal["LM", "SM"] = "LM", irl_mode: bool = True, kmax: int | None = None, compute_u: bool = True, compute_v: bool = True, - v0: npt.ArrayLike | None = None, + v0: onp.ToComplexND | None = None, full_output: bool = False, tol: float = 0, delta: float | None = None, diff --git a/scipy-stubs/spatial/_ckdtree.pyi b/scipy-stubs/spatial/_ckdtree.pyi index 43141768..eb14f9e1 100644 --- a/scipy-stubs/spatial/_ckdtree.pyi +++ b/scipy-stubs/spatial/_ckdtree.pyi @@ -1,7 +1,6 @@ from typing import Literal as L, TypeAlias, overload, type_check_only import numpy as np -import numpy.typing as npt import optype.numpy as onp from scipy.sparse import coo_matrix, dok_matrix @@ -66,12 +65,12 @@ class cKDTree(_CythonMixin): def __init__( self, /, - data: npt.ArrayLike, + data: onp.ToComplexND, leafsize: int = ..., compact_nodes: bool = ..., copy_data: bool = ..., balanced_tree: bool = ..., - boxsize: npt.ArrayLike | None = ..., + boxsize: onp.ToFloat2D | None = ..., ) -> None: ... # @@ -176,7 +175,7 @@ class cKDTree(_CythonMixin): self, /, other: cKDTree, - r: npt.ArrayLike, + r: onp.ToFloat | onp.ToFloatND, p: onp.ToFloat = 2.0, weights: tuple[None, None] | None = ..., cumulative: bool = True, @@ -186,7 +185,7 @@ class cKDTree(_CythonMixin): self, /, other: cKDTree, - r: npt.ArrayLike, + r: onp.ToFloat | onp.ToFloatND, p: onp.ToFloat, weights: _Weights, cumulative: bool = True, @@ -196,7 +195,7 @@ class cKDTree(_CythonMixin): self, /, other: cKDTree, - r: npt.ArrayLike, + r: onp.ToFloat | onp.ToFloatND, p: onp.ToFloat = 2.0, *, weights: _Weights, diff --git a/scipy-stubs/spatial/_procrustes.pyi b/scipy-stubs/spatial/_procrustes.pyi index 1e872a9d..77d0730d 100644 --- a/scipy-stubs/spatial/_procrustes.pyi +++ b/scipy-stubs/spatial/_procrustes.pyi @@ -1,10 +1,9 @@ import numpy as np -import numpy.typing as npt import optype.numpy as onp __all__ = ["procrustes"] def procrustes( - data1: npt.ArrayLike, - data2: npt.ArrayLike, + data1: onp.ToFloat2D, + data2: onp.ToFloat2D, ) -> tuple[onp.ArrayND[np.float64], onp.ArrayND[np.float64], np.float64]: ... diff --git a/scipy-stubs/spatial/distance.pyi b/scipy-stubs/spatial/distance.pyi index f5502ee6..78be7132 100644 --- a/scipy-stubs/spatial/distance.pyi +++ b/scipy-stubs/spatial/distance.pyi @@ -4,7 +4,6 @@ from typing import Any, Literal, Protocol, TypeAlias, overload, type_check_only from typing_extensions import Buffer import numpy as np -import numpy.typing as npt import optype.numpy as onp import optype.typing as opt @@ -112,92 +111,92 @@ _MetricKind: TypeAlias = Literal[ # Function annotations -def braycurtis(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> np.float64: ... -def canberra(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> np.float64: ... +def braycurtis(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None) -> np.float64: ... +def canberra(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None) -> np.float64: ... # TODO: Add `metric`-specific overloads # Returns a float64 or float128 array, depending on the input dtype @overload def cdist( - XA: npt.ArrayLike, - XB: npt.ArrayLike, + XA: onp.ToFloat2D, + XB: onp.ToFloat2D, metric: _MetricKind = "euclidean", *, out: onp.ArrayND[np.floating[Any]] | None = None, p: float = 2, - w: npt.ArrayLike | None = None, - V: npt.ArrayLike | None = None, - VI: npt.ArrayLike | None = None, + w: onp.ToFloat1D | None = None, + V: onp.ToFloat2D | None = None, + VI: onp.ToFloat2D | None = None, ) -> onp.ArrayND[np.floating[Any]]: ... @overload def cdist( - XA: npt.ArrayLike, - XB: npt.ArrayLike, + XA: onp.ToFloat2D, + XB: onp.ToFloat2D, metric: _MetricCallback, *, out: onp.ArrayND[np.floating[Any]] | None = None, **kwargs: object, ) -> onp.ArrayND[np.floating[Any]]: ... -def chebyshev(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> np.number[Any]: ... -def cityblock(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> np.number[Any]: ... -def correlation(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None, centered: bool = True) -> np.float64: ... -def cosine(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> np.float64: ... -def dice(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> float: ... -def directed_hausdorff(u: npt.ArrayLike, v: npt.ArrayLike, seed: int | None = 0) -> tuple[float, int, int]: ... -def euclidean(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> float: ... -def hamming(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> np.float64: ... +def chebyshev(u: onp.ToComplex1D, v: onp.ToComplex1D, w: onp.ToComplex1D | None = None) -> np.number[Any]: ... +def cityblock(u: onp.ToComplex1D, v: onp.ToComplex1D, w: onp.ToComplex1D | None = None) -> np.number[Any]: ... +def correlation(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None, centered: bool = True) -> np.float64: ... +def cosine(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None) -> np.float64: ... +def dice(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None) -> float: ... +def directed_hausdorff(u: onp.ToFloat1D, v: onp.ToFloat1D, seed: int | None = 0) -> tuple[float, int, int]: ... +def euclidean(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None) -> float: ... +def hamming(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None) -> np.float64: ... def is_valid_dm( - D: npt.ArrayLike, + D: onp.ToFloat2D, tol: float = 0.0, throw: bool = False, name: str | None = "D", warning: bool = False, ) -> bool: ... -def is_valid_y(y: npt.ArrayLike, warning: bool = False, throw: bool = False, name: str | None = None) -> bool: ... -def jaccard(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> np.float64: ... +def is_valid_y(y: onp.ToFloat1D, warning: bool = False, throw: bool = False, name: str | None = None) -> bool: ... +def jaccard(u: onp.ToBool1D, v: onp.ToBool1D, w: onp.ToBool1D | None = None) -> np.float64: ... def jensenshannon( - p: npt.ArrayLike, - q: npt.ArrayLike, + p: onp.ToFloat1D, + q: onp.ToFloat1D, base: float | None = None, *, axis: int = 0, keepdims: bool = False, ) -> np.float64: ... -def kulczynski1(u: npt.ArrayLike, v: npt.ArrayLike, *, w: npt.ArrayLike | None = None) -> np.float64: ... -def mahalanobis(u: npt.ArrayLike, v: npt.ArrayLike, VI: npt.ArrayLike) -> np.float64: ... -def minkowski(u: npt.ArrayLike, v: npt.ArrayLike, p: float = 2, w: npt.ArrayLike | None = None) -> float: ... -def num_obs_dm(d: npt.ArrayLike) -> int: ... -def num_obs_y(Y: npt.ArrayLike) -> int: ... +def kulczynski1(u: onp.ToFloat1D, v: onp.ToFloat1D, *, w: onp.ToFloat1D | None = None) -> np.float64: ... +def mahalanobis(u: onp.ToFloat1D, v: onp.ToFloat1D, VI: onp.ToFloat2D) -> np.float64: ... +def minkowski(u: onp.ToFloat1D, v: onp.ToFloat1D, p: float = 2, w: onp.ToFloat1D | None = None) -> float: ... +def num_obs_dm(d: onp.ToFloat1D) -> int: ... +def num_obs_y(Y: onp.ToFloat1D) -> int: ... # TODO: Add `metric`-specific overloads @overload def pdist( - X: npt.ArrayLike, + X: onp.ToFloat2D, metric: _MetricKind = "euclidean", *, out: onp.ArrayND[np.floating[Any]] | None = None, p: float = 2, - w: npt.ArrayLike | None = None, - V: npt.ArrayLike | None = None, - VI: npt.ArrayLike | None = None, + w: onp.ToFloat1D | None = None, + V: onp.ToFloat2D | None = None, + VI: onp.ToFloat2D | None = None, ) -> onp.ArrayND[np.floating[Any]]: ... @overload def pdist( - X: npt.ArrayLike, + X: onp.ToFloat2D, metric: _MetricCallback, *, out: onp.ArrayND[np.floating[Any]] | None = None, **kwargs: object, ) -> onp.ArrayND[np.floating[Any]]: ... -def seuclidean(u: npt.ArrayLike, v: npt.ArrayLike, V: npt.ArrayLike) -> float: ... -def sokalmichener(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> float: ... -def sokalsneath(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> np.float64: ... -def sqeuclidean(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> np.float64: ... +def seuclidean(u: onp.ToFloat1D, v: onp.ToFloat1D, V: onp.ToFloat1D) -> float: ... +def sokalmichener(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None) -> float: ... +def sokalsneath(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None) -> np.float64: ... +def sqeuclidean(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None) -> np.float64: ... def squareform( - X: npt.ArrayLike, + X: onp.ToFloat2D, force: Literal["no", "tomatrix", "tovector"] = "no", checks: bool = True, -) -> onp.ArrayND: ... -def rogerstanimoto(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> float: ... -def russellrao(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> float: ... -def yule(u: npt.ArrayLike, v: npt.ArrayLike, w: npt.ArrayLike | None = None) -> float: ... +) -> onp.Array1D[np.floating[Any]] | onp.Array2D[np.floating[Any]]: ... +def rogerstanimoto(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None) -> float: ... +def russellrao(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None) -> float: ... +def yule(u: onp.ToFloat1D, v: onp.ToFloat1D, w: onp.ToFloat1D | None = None) -> float: ... diff --git a/scipy-stubs/spatial/transform/_rotation.pyi b/scipy-stubs/spatial/transform/_rotation.pyi index bc84f75a..ae6b9b86 100644 --- a/scipy-stubs/spatial/transform/_rotation.pyi +++ b/scipy-stubs/spatial/transform/_rotation.pyi @@ -1,33 +1,42 @@ from collections.abc import Sequence import numpy as np -import numpy.typing as npt import optype.numpy as onp from scipy._typing import Seed class Rotation: @property def single(self, /) -> bool: ... - def __init__(self, /, quat: npt.ArrayLike, normalize: bool = ..., copy: bool = ...) -> None: ... + def __init__(self, /, quat: onp.ToComplex | onp.ToComplexND, normalize: bool = ..., copy: bool = ...) -> None: ... def __setstate_cython__(self, pyx_state: object, /) -> None: ... def __reduce_cython__(self, /) -> None: ... def __len__(self, /) -> int: ... - def __getitem__(self, /, indexer: int | slice | npt.ArrayLike) -> Rotation: ... + def __getitem__(self, /, indexer: int | slice | onp.ToComplex | onp.ToComplexND) -> Rotation: ... def __mul__(self, /, other: Rotation) -> Rotation: ... def __pow__(self, /, n: float, modulus: int | None) -> Rotation: ... def as_quat(self, /, canonical: bool = ..., *, scalar_first: bool = ...) -> onp.ArrayND[np.float64]: ... def as_matrix(self, /) -> onp.ArrayND[np.float64]: ... def as_rotvec(self, /, degrees: bool = ...) -> onp.ArrayND[np.float64]: ... def as_euler(self, /, seq: str, degrees: bool = ...) -> onp.ArrayND[np.float64]: ... - def as_davenport(self, /, axes: npt.ArrayLike, order: str, degrees: bool = ...) -> onp.ArrayND[np.float64]: ... + def as_davenport( + self, + /, + axes: onp.ToComplex | onp.ToComplexND, + order: str, + degrees: bool = ..., + ) -> onp.ArrayND[np.float64]: ... def as_mrp(self, /) -> onp.ArrayND[np.float64]: ... - def apply(self, /, vectors: npt.ArrayLike, inverse: bool = ...) -> onp.ArrayND[np.float64]: ... + def apply(self, /, vectors: onp.ToComplex | onp.ToComplexND, inverse: bool = ...) -> onp.ArrayND[np.float64]: ... def inv(self, /) -> Rotation: ... def magnitude(self, /) -> onp.ArrayND[np.float64] | float: ... def approx_equal( - self, /, other: Rotation, atol: float | None = None, degrees: bool = ... + self, + /, + other: Rotation, + atol: float | None = None, + degrees: bool = ..., ) -> onp.ArrayND[np.bool_] | bool: ... - def mean(self, /, weights: npt.ArrayLike | None = ...) -> Rotation: ... + def mean(self, /, weights: onp.ToComplex | onp.ToComplexND | None = ...) -> Rotation: ... def reduce( self, /, @@ -36,17 +45,23 @@ class Rotation: return_indices: bool = ..., ) -> Rotation | tuple[Rotation, onp.ArrayND[np.float64], onp.ArrayND[np.float64]]: ... @classmethod - def from_quat(cls, quat: npt.ArrayLike, *, scalar_first: bool = ...) -> Rotation: ... + def from_quat(cls, quat: onp.ToComplex | onp.ToComplexND, *, scalar_first: bool = ...) -> Rotation: ... @classmethod - def from_matrix(cls, matrix: npt.ArrayLike) -> Rotation: ... + def from_matrix(cls, matrix: onp.ToComplex | onp.ToComplexND) -> Rotation: ... @classmethod - def from_rotvec(cls, rotvec: npt.ArrayLike, degrees: bool = ...) -> Rotation: ... + def from_rotvec(cls, rotvec: onp.ToComplex | onp.ToComplexND, degrees: bool = ...) -> Rotation: ... @classmethod - def from_euler(cls, seq: str, angles: float | npt.ArrayLike, degrees: bool = ...) -> Rotation: ... + def from_euler(cls, seq: str, angles: float | onp.ToComplex | onp.ToComplexND, degrees: bool = ...) -> Rotation: ... @classmethod - def from_davenport(cls, axes: npt.ArrayLike, order: str, angles: float | npt.ArrayLike, degrees: bool = ...) -> Rotation: ... + def from_davenport( + cls, + axes: onp.ToComplex | onp.ToComplexND, + order: str, + angles: float | onp.ToComplex | onp.ToComplexND, + degrees: bool = ..., + ) -> Rotation: ... @classmethod - def from_mrp(cls, mrp: npt.ArrayLike) -> Rotation: ... + def from_mrp(cls, mrp: onp.ToComplex | onp.ToComplexND) -> Rotation: ... @classmethod def concatenate(cls, rotations: Sequence[Rotation]) -> Rotation: ... @classmethod @@ -58,9 +73,9 @@ class Rotation: @classmethod def align_vectors( cls, - a: npt.ArrayLike, - b: npt.ArrayLike, - weights: npt.ArrayLike | None = ..., + a: onp.ToComplex | onp.ToComplexND, + b: onp.ToComplex | onp.ToComplexND, + weights: onp.ToComplex | onp.ToComplexND | None = ..., return_sensitivity: bool = ..., ) -> tuple[Rotation, float] | tuple[Rotation, float, onp.ArrayND[np.float64]]: ... @@ -69,5 +84,5 @@ class Slerp: timedelta: onp.ArrayND rotations: Rotation rotvecs: onp.ArrayND[np.float64] - def __init__(self, /, times: npt.ArrayLike, rotations: Rotation) -> None: ... - def __call__(self, /, times: npt.ArrayLike) -> Rotation: ... + def __init__(self, /, times: onp.ToComplex | onp.ToComplexND, rotations: Rotation) -> None: ... + def __call__(self, /, times: onp.ToComplex | onp.ToComplexND) -> Rotation: ... diff --git a/scipy-stubs/spatial/transform/_rotation_spline.pyi b/scipy-stubs/spatial/transform/_rotation_spline.pyi index f6a68b3f..f810175b 100644 --- a/scipy-stubs/spatial/transform/_rotation_spline.pyi +++ b/scipy-stubs/spatial/transform/_rotation_spline.pyi @@ -1,5 +1,4 @@ import numpy as np -import numpy.typing as npt import optype.numpy as onp from scipy.interpolate import PPoly from ._rotation import Rotation @@ -7,8 +6,10 @@ from ._rotation import Rotation class RotationSpline: MAX_ITER: int TOL: float - times: onp.ArrayND[np.float64] + + times: onp.Array1D[np.float64] rotations: Rotation interpolator: PPoly - def __init__(self, /, times: npt.ArrayLike, rotations: Rotation) -> None: ... - def __call__(self, /, times: npt.ArrayLike, order: int = ...) -> Rotation | onp.ArrayND[np.float64]: ... + + def __init__(self, /, times: onp.ToFloat1D, rotations: Rotation) -> None: ... + def __call__(self, /, times: onp.ToFloat1D, order: int = ...) -> Rotation | onp.ArrayND[np.float64]: ... diff --git a/scipy-stubs/spatial/transform/rotation.pyi b/scipy-stubs/spatial/transform/rotation.pyi index 6f659d93..8605cdc3 100644 --- a/scipy-stubs/spatial/transform/rotation.pyi +++ b/scipy-stubs/spatial/transform/rotation.pyi @@ -1,79 +1,9 @@ -# pyright: reportDeprecated=false -# This file is not meant for public use and will be removed in SciPy v2.0.0. - -from collections.abc import Sequence -from typing import Any, TypeAlias from typing_extensions import deprecated -import numpy as np -import numpy.typing as npt -import optype.numpy as onp - -_IntegerType: TypeAlias = int | np.integer[Any] +from . import _rotation @deprecated("will be removed in SciPy v2.0.0") -class Rotation: - def __init__(self, /, quat: npt.ArrayLike, normalize: bool = ..., copy: bool = ...) -> None: ... - @property - def single(self, /) -> bool: ... - def __len__(self, /) -> int: ... - @classmethod - def from_quat(cls, quat: npt.ArrayLike, *, scalar_first: bool = ...) -> Rotation: ... - @classmethod - def from_matrix(cls, matrix: npt.ArrayLike) -> Rotation: ... - @classmethod - def from_rotvec(cls, rotvec: npt.ArrayLike, degrees: bool = ...) -> Rotation: ... - @classmethod - def from_euler(cls, seq: str, angles: float | npt.ArrayLike, degrees: bool = ...) -> Rotation: ... - @classmethod - def from_davenport(cls, axes: npt.ArrayLike, order: str, angles: float | npt.ArrayLike, degrees: bool = ...) -> Rotation: ... - @classmethod - def from_mrp(cls, mrp: npt.ArrayLike) -> Rotation: ... - def as_quat(self, /, canonical: bool = ..., *, scalar_first: bool = ...) -> onp.ArrayND[np.float64]: ... - def as_matrix(self, /) -> onp.ArrayND[np.float64]: ... - def as_rotvec(self, /, degrees: bool = ...) -> onp.ArrayND[np.float64]: ... - def as_euler(self, /, seq: str, degrees: bool = ...) -> onp.ArrayND[np.float64]: ... - def as_davenport(self, /, axes: npt.ArrayLike, order: str, degrees: bool = ...) -> onp.ArrayND[np.float64]: ... - def as_mrp(self, /) -> onp.ArrayND[np.float64]: ... - @classmethod - def concatenate(cls, rotations: Sequence[Rotation]) -> Rotation: ... - def apply(self, /, vectors: npt.ArrayLike, inverse: bool = ...) -> onp.ArrayND[np.float64]: ... - def __mul__(self, /, other: Rotation) -> Rotation: ... - def __pow__(self, /, n: float, modulus: int | None) -> Rotation: ... - def inv(self, /) -> Rotation: ... - def magnitude(self, /) -> onp.ArrayND[np.float64] | float: ... - def approx_equal(self, /, other: Rotation, atol: float | None = ..., degrees: bool = ...) -> onp.ArrayND[np.bool_] | bool: ... - def mean(self, /, weights: npt.ArrayLike | None = ...) -> Rotation: ... - def reduce( - self, - /, - left: Rotation | None = ..., - right: Rotation | None = ..., - return_indices: bool = ..., - ) -> Rotation | tuple[Rotation, onp.ArrayND[np.float64], onp.ArrayND[np.float64]]: ... - @classmethod - def create_group(cls, group: str, axis: str = ...) -> Rotation: ... - def __getitem__(self, /, indexer: int | slice | npt.ArrayLike) -> Rotation: ... - @classmethod - def identity(cls, num: int | None = ...) -> Rotation: ... - @classmethod - def random( - cls, - num: int | None = ..., - random_state: _IntegerType | np.random.Generator | np.random.RandomState | None = ..., - ) -> Rotation: ... - @classmethod - def align_vectors( - cls, - a: npt.ArrayLike, - b: npt.ArrayLike, - weights: npt.ArrayLike | None = ..., - return_sensitivity: bool = ..., - ) -> tuple[Rotation, float] | tuple[Rotation, float, onp.ArrayND[np.float64]]: ... - def __reduce_cython__(self, /) -> object: ... - def __setstate_cython__(self, __pyx_state: object, /) -> object: ... +class Rotation(_rotation.Rotation): ... @deprecated("will be removed in SciPy v2.0.0") -class Slerp: - def __init__(self, /, times: npt.ArrayLike, rotations: Rotation) -> None: ... - def __call__(self, /, times: npt.ArrayLike) -> Rotation: ... +class Slerp(_rotation.Slerp): ... diff --git a/scipy-stubs/special/_orthogonal.pyi b/scipy-stubs/special/_orthogonal.pyi index 52d23578..47104811 100644 --- a/scipy-stubs/special/_orthogonal.pyi +++ b/scipy-stubs/special/_orthogonal.pyi @@ -1,9 +1,7 @@ -from collections.abc import Callable, Sequence +from collections.abc import Callable from typing import Any, Literal, TypeAlias, overload -from typing_extensions import TypeVar import numpy as np -import numpy.typing as npt import optype.numpy as onp _PointsWeights: TypeAlias = tuple[onp.ArrayND[np.float64], onp.ArrayND[np.float64]] @@ -57,8 +55,6 @@ __all__ = [ "us_roots", ] -_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...]) - # mypy: disable-error-code="explicit-override" class orthopoly1d(np.poly1d): limits: tuple[float, float] @@ -68,8 +64,8 @@ class orthopoly1d(np.poly1d): def __init__( self, /, - roots: npt.ArrayLike, - weights: npt.ArrayLike | None = None, + roots: onp.ToComplex1D, + weights: onp.ToFloat1D | None = None, hn: float = 1.0, kn: float = 1.0, wfunc: Callable[[float], float] | None = None, @@ -84,11 +80,9 @@ class orthopoly1d(np.poly1d): @overload def __call__(self, /, v: onp.ToComplex) -> np.inexact[Any]: ... @overload - def __call__( # pyright: ignore[reportIncompatibleMethodOverride] - self, - /, - v: onp.CanArray[_ShapeT, np.dtype[np.floating[Any] | np.integer[Any] | np.bool_]] | Sequence[npt.ArrayLike], - ) -> onp.Array[_ShapeT, np.floating[Any]]: ... + def __call__(self, /, v: onp.ToFloatND) -> onp.ArrayND[np.floating[Any]]: ... + @overload + def __call__(self, /, v: onp.ToComplexND) -> onp.ArrayND[np.inexact[Any]]: ... # pyright: ignore[reportIncompatibleMethodOverride] @overload def roots_jacobi(n: onp.ToInt, alpha: onp.ToFloat, beta: onp.ToFloat, mu: Literal[False] = ...) -> _PointsWeights: ... diff --git a/scipy-stubs/special/_ufuncs.pyi b/scipy-stubs/special/_ufuncs.pyi index 72033960..73dd4d8b 100644 --- a/scipy-stubs/special/_ufuncs.pyi +++ b/scipy-stubs/special/_ufuncs.pyi @@ -1,5 +1,5 @@ # mypy: disable-error-code="explicit-override, override, misc" -# pyright: reportIncompatibleMethodOverride=false, reportIncompatibleVariableOverride=false +# pyright: reportIncompatibleMethodOverride=false, reportIncompatibleVariableOverride=false, reportImplicitOverride=false from types import EllipsisType from typing import Any, Generic, Literal as L, TypeAlias, TypedDict, final, overload, type_check_only @@ -597,7 +597,6 @@ class _UFunc21ld(_UFunc21[_NameT_co, _IdentityT_co], Generic[_NameT_co, _Identit def accumulate(self, /, *args: Never, **kwargs: Never) -> Never: ... @override def reduce(self, /, *args: Never, **kwargs: Never) -> Never: ... - @override def reduceat(self, /, *args: Never, **kwargs: Never) -> Never: ... @final @@ -732,7 +731,6 @@ class _UFunc21f(_UFunc21[_NameT_co, _IdentityT_co], Generic[_NameT_co, _Identity where: onp.ToBool | onp.ToBoolND = True, ) -> _OutT: ... # - @override def reduceat( self, /, @@ -910,7 +908,6 @@ class _UFunc21fc1(_UFunc21[_NameT_co, _IdentityT_co], Generic[_NameT_co, _Identi where: onp.ToBool | onp.ToBoolND = True, ) -> _OutT: ... # - @override def reduceat( self, /, diff --git a/scipy-stubs/stats/_binned_statistic.pyi b/scipy-stubs/stats/_binned_statistic.pyi index 6f2fef62..ed840e44 100644 --- a/scipy-stubs/stats/_binned_statistic.pyi +++ b/scipy-stubs/stats/_binned_statistic.pyi @@ -2,7 +2,6 @@ from collections.abc import Callable, Sequence from typing import Any, Literal, NamedTuple, TypeAlias import numpy as np -import numpy.typing as npt import optype.numpy as onp __all__ = ["binned_statistic", "binned_statistic_2d", "binned_statistic_dd"] @@ -15,10 +14,10 @@ class BinnedStatisticResult(NamedTuple): binnumber: onp.Array1D[np.intp] def binned_statistic( - x: npt.ArrayLike, - values: npt.ArrayLike, - statistic: _Statistic | Callable[[onp.ArrayND[np.float64]], np.float64 | float] = "mean", - bins: int = 10, + x: onp.ToComplex1D, + values: onp.ToComplex1D | Sequence[onp.ToComplex1D], + statistic: _Statistic | Callable[[onp.Array1D[np.float64]], onp.ToFloat] = "mean", + bins: onp.ToInt | onp.ToFloat1D = 10, range: tuple[float, float] | Sequence[tuple[float, float]] | None = None, ) -> BinnedStatisticResult: ... @@ -29,11 +28,11 @@ class BinnedStatistic2dResult(NamedTuple): binnumber: onp.Array1D[np.intp] def binned_statistic_2d( - x: npt.ArrayLike, - y: npt.ArrayLike, - values: npt.ArrayLike, - statistic: _Statistic | Callable[[onp.ArrayND[np.float64]], np.float64 | float] = "mean", - bins: npt.ArrayLike = 10, + x: onp.ToComplex1D, + y: onp.ToComplex1D, + values: onp.ToComplex1D | Sequence[onp.ToComplex1D], + statistic: _Statistic | Callable[[onp.ArrayND[np.float64]], onp.ToFloat] = "mean", + bins: onp.ToInt | onp.ToFloat1D | Sequence[onp.ToFloat1D] = 10, range: tuple[int, int] | None = None, expand_binnumbers: bool = False, ) -> BinnedStatistic2dResult: ... @@ -44,10 +43,10 @@ class BinnedStatisticddResult(NamedTuple): binnumber: onp.Array1D[np.intp] | onp.Array2D[np.intp] def binned_statistic_dd( - sample: npt.ArrayLike, - values: npt.ArrayLike, - statistic: _Statistic | Callable[[onp.ArrayND[np.float64]], np.float64 | float] = "mean", - bins: npt.ArrayLike = 10, + sample: onp.ToComplex2D, + values: onp.ToComplex1D | Sequence[onp.ToComplex1D], + statistic: _Statistic | Callable[[onp.ArrayND[np.float64]], onp.ToFloat] = "mean", + bins: onp.ToInt | onp.ToFloat1D = 10, range: tuple[int, int] | None = None, expand_binnumbers: bool = False, binned_statistic_result: BinnedStatisticddResult | None = None, diff --git a/scipy-stubs/stats/_bws_test.pyi b/scipy-stubs/stats/_bws_test.pyi index a58aee62..31bb442c 100644 --- a/scipy-stubs/stats/_bws_test.pyi +++ b/scipy-stubs/stats/_bws_test.pyi @@ -1,11 +1,11 @@ from typing import Literal -import numpy.typing as npt +import optype.numpy as onp from ._resampling import PermutationMethod, PermutationTestResult def bws_test( - x: npt.ArrayLike, - y: npt.ArrayLike, + x: onp.ToComplex1D, + y: onp.ToComplex1D, *, alternative: Literal["two-sided", "less", "greater"] = "two-sided", method: PermutationMethod | None = None, diff --git a/scipy-stubs/stats/_censored_data.pyi b/scipy-stubs/stats/_censored_data.pyi index e947ff5c..ab27b75b 100644 --- a/scipy-stubs/stats/_censored_data.pyi +++ b/scipy-stubs/stats/_censored_data.pyi @@ -1,25 +1,24 @@ from typing_extensions import Self -import numpy.typing as npt import optype.numpy as onp class CensoredData: def __init__( self, /, - uncensored: npt.ArrayLike | None = None, + uncensored: onp.ToComplex1D | None = None, *, - left: npt.ArrayLike | None = None, - right: npt.ArrayLike | None = None, - interval: npt.ArrayLike | None = None, + left: onp.ToComplex1D | None = None, + right: onp.ToComplex1D | None = None, + interval: onp.ToFloat2D | None = None, ) -> None: ... def __sub__(self, other: object, /) -> CensoredData: ... def __truediv__(self, other: object, /) -> CensoredData: ... def __len__(self, /) -> int: ... def num_censored(self, /) -> int: ... @classmethod - def right_censored(cls, x: npt.ArrayLike, censored: onp.AnyBoolArray) -> Self: ... + def right_censored(cls, x: onp.ToComplex1D, censored: onp.ToBool1D) -> Self: ... @classmethod - def left_censored(cls, x: npt.ArrayLike, censored: onp.AnyBoolArray) -> Self: ... + def left_censored(cls, x: onp.ToComplex1D, censored: onp.ToBool1D) -> Self: ... @classmethod - def interval_censored(cls, low: npt.ArrayLike, high: npt.ArrayLike) -> Self: ... + def interval_censored(cls, low: onp.ToComplex1D, high: onp.ToComplex1D) -> Self: ... diff --git a/scipy-stubs/stats/_entropy.pyi b/scipy-stubs/stats/_entropy.pyi index 8fe18de3..6dfe59e8 100644 --- a/scipy-stubs/stats/_entropy.pyi +++ b/scipy-stubs/stats/_entropy.pyi @@ -4,28 +4,28 @@ from typing import Any, Literal import numpy as np -import numpy.typing as npt +import optype as op import optype.numpy as onp import scipy._typing as spt __all__ = ["differential_entropy", "entropy"] def entropy( - pk: npt.ArrayLike, - qk: npt.ArrayLike | None = None, - base: float | None = None, + pk: onp.ToFloatND, + qk: onp.ToFloatND | None = None, + base: onp.ToFloat | None = None, axis: int = 0, *, nan_policy: spt.NanPolicy = "propagate", - keepdims: bool = False, -) -> np.floating[Any] | onp.ArrayND[np.floating[Any]]: ... + keepdims: onp.ToBool = False, +) -> float | np.floating[Any] | onp.ArrayND[np.floating[Any]]: ... def differential_entropy( - values: npt.ArrayLike, + values: onp.ToFloatND, *, - window_length: int | None = None, - base: float | None = None, - axis: int = 0, + window_length: onp.ToInt | None = None, + base: onp.ToFloat | None = None, + axis: op.CanIndex = 0, method: Literal["vasicek", "van es", "ebrahimi", "correa", "auto"] = "auto", nan_policy: spt.NanPolicy = "propagate", - keepdims: bool = False, -) -> np.floating[Any] | onp.ArrayND[np.floating[Any]]: ... + keepdims: onp.ToBool = False, +) -> float | np.floating[Any] | onp.ArrayND[np.floating[Any]]: ... diff --git a/scipy-stubs/stats/_morestats.pyi b/scipy-stubs/stats/_morestats.pyi index 05a4f69f..d9c8076b 100644 --- a/scipy-stubs/stats/_morestats.pyi +++ b/scipy-stubs/stats/_morestats.pyi @@ -4,7 +4,6 @@ from typing import Any, Generic, Literal, NamedTuple, Protocol, TypeAlias, final from typing_extensions import Self, TypeVar import numpy as np -import numpy.typing as npt import optype as op import optype.numpy as onp from scipy._typing import Alternative, AnyBool, NanPolicy @@ -70,7 +69,7 @@ class _ConfidenceInterval(NamedTuple): @type_check_only class _CanPlotText(Protocol): # NOTE: `Any` is required as return type because it's covariant, and not shouldn't be `Never`. - def plot(self, /, *args: float | npt.ArrayLike | str, **kwargs: object) -> Any: ... # noqa: ANN401 + def plot(self, /, *args: float | onp.ToFloatND | str, **kwargs: object) -> Any: ... # noqa: ANN401 def text(self, /, x: float, y: float, s: str, fontdict: dict[str, Any] | None = None, **kwargs: object) -> Any: ... # noqa: ANN401 @type_check_only diff --git a/scipy-stubs/stats/_mstats_basic.pyi b/scipy-stubs/stats/_mstats_basic.pyi index ac55b0d9..c4ccf197 100644 --- a/scipy-stubs/stats/_mstats_basic.pyi +++ b/scipy-stubs/stats/_mstats_basic.pyi @@ -162,8 +162,6 @@ def mode(a: onp.ToFloatND, axis: op.CanIndex | None = 0) -> ModeResult: ... # @overload -def msign(x: onp.Array[_ShapeT, _SCT_bifcmO]) -> onp.Array[_ShapeT, _SCT_bifcmO]: ... -@overload def msign(x: _ArrayLike[_SCT_bifcmO]) -> onp.ArrayND[_SCT_bifcmO]: ... @overload def msign(x: onp.ToComplexND) -> onp.ArrayND[np.number[Any] | np.timedelta64 | np.bool_ | np.object_]: ... diff --git a/scipy-stubs/stats/_multicomp.pyi b/scipy-stubs/stats/_multicomp.pyi index aed2c10e..d10b2f84 100644 --- a/scipy-stubs/stats/_multicomp.pyi +++ b/scipy-stubs/stats/_multicomp.pyi @@ -2,7 +2,6 @@ from dataclasses import dataclass from typing import Any, Literal import numpy as np -import numpy.typing as npt import optype.numpy as onp from scipy._typing import Alternative, Seed from ._common import ConfidenceInterval @@ -28,8 +27,8 @@ class DunnettResult: def confidence_interval(self, /, confidence_level: onp.ToFloat = 0.95) -> ConfidenceInterval: ... def dunnett( - *samples: npt.ArrayLike, - control: npt.ArrayLike, + *samples: onp.ToFloat1D, + control: onp.ToFloat1D, alternative: Alternative = "two-sided", random_state: Seed | None = None, ) -> DunnettResult: ... diff --git a/scipy-stubs/stats/_sensitivity_analysis.pyi b/scipy-stubs/stats/_sensitivity_analysis.pyi index 3d6f467e..8705bfef 100644 --- a/scipy-stubs/stats/_sensitivity_analysis.pyi +++ b/scipy-stubs/stats/_sensitivity_analysis.pyi @@ -3,7 +3,6 @@ from collections.abc import Callable, Mapping, Sequence from typing import Any, Literal, Protocol, TypeAlias import numpy as np -import numpy.typing as npt import optype.numpy as onp from scipy._typing import Seed from ._resampling import BootstrapResult @@ -13,7 +12,7 @@ __all__ = ["sobol_indices"] _SobolKey: TypeAlias = Literal["f_A", "f_B", "f_AB"] _SobolMethod: TypeAlias = Callable[ [onp.ArrayND[np.float64], onp.ArrayND[np.float64], onp.ArrayND[np.float64]], - tuple[npt.ArrayLike, npt.ArrayLike], + tuple[onp.ToFloat | onp.ToFloatND, onp.ToFloat | onp.ToFloatND], ] ### @@ -44,7 +43,7 @@ class SobolResult: def bootstrap(self, /, confidence_level: onp.ToFloat = 0.95, n_resamples: onp.ToInt = 999) -> BootstrapSobolResult: ... # -def f_ishigami(x: npt.ArrayLike) -> onp.ArrayND[np.floating[Any]]: ... +def f_ishigami(x: onp.ToFloat2D) -> onp.Array1D[np.floating[Any]]: ... # def sample_A_B(n: onp.ToInt, dists: Sequence[PPFDist], random_state: Seed | None = None) -> onp.ArrayND[np.float64]: ... @@ -60,7 +59,7 @@ def saltelli_2010( # def sobol_indices( *, - func: Callable[[onp.ArrayND[np.float64]], npt.ArrayLike] | Mapping[_SobolKey, onp.ArrayND[np.number[Any]]], + func: Callable[[onp.Array2D[np.float64]], onp.ToComplex2D] | Mapping[_SobolKey, onp.Array2D[np.number[Any]]], n: onp.ToInt, dists: Sequence[PPFDist] | None = None, method: _SobolMethod | Literal["saltelli_2010"] = "saltelli_2010", diff --git a/scipy-stubs/stats/_stats_mstats_common.pyi b/scipy-stubs/stats/_stats_mstats_common.pyi index 5cc10f4b..a708cbdd 100644 --- a/scipy-stubs/stats/_stats_mstats_common.pyi +++ b/scipy-stubs/stats/_stats_mstats_common.pyi @@ -2,7 +2,6 @@ from typing import Any, Literal, TypeAlias from typing_extensions import Self import numpy as np -import numpy.typing as npt import optype.numpy as onp from . import distributions as distributions from ._typing import BaseBunch @@ -33,13 +32,13 @@ class TheilslopesResult(BaseBunch[np.float64, np.float64, np.float64, np.float64 def _find_repeats(arr: onp.ArrayND[np.number[Any]]) -> tuple[onp.ArrayND[np.float64], onp.ArrayND[np.intp]]: ... def siegelslopes( - y: npt.ArrayLike, - x: npt.ArrayLike | None = None, + y: onp.ToFloatND, + x: onp.ToFloat1D | None = None, method: _Method = "hierarchical", ) -> SiegelslopesResult: ... def theilslopes( - y: npt.ArrayLike, - x: npt.ArrayLike | None = None, + y: onp.ToFloatND, + x: onp.ToFloat1D | None = None, alpha: float | np.floating[Any] = 0.95, method: _Method = "separate", ) -> TheilslopesResult: ... diff --git a/scipy-stubs/stats/_unuran/unuran_wrapper.pyi b/scipy-stubs/stats/_unuran/unuran_wrapper.pyi index 2e0ed95a..e9fc4a4a 100644 --- a/scipy-stubs/stats/_unuran/unuran_wrapper.pyi +++ b/scipy-stubs/stats/_unuran/unuran_wrapper.pyi @@ -2,7 +2,6 @@ from collections.abc import Callable from typing import NamedTuple, Protocol, overload, type_check_only import numpy as np -import numpy.typing as npt import optype.numpy as onp import scipy.stats as stats from scipy._typing import Seed @@ -44,7 +43,7 @@ class _PPFMethodMixin: @overload def ppf(self, /, u: onp.ToFloat) -> float: ... @overload - def ppf(self, /, u: npt.ArrayLike) -> float | onp.ArrayND[np.float64]: ... + def ppf(self, /, u: onp.ToFloatND) -> onp.ArrayND[np.float64]: ... class UNURANError(RuntimeError): ... @@ -69,7 +68,7 @@ class TransformedDensityRejection(Method): center: float | None = ..., domain: tuple[float, float] | None = ..., c: float = ..., - construction_points: npt.ArrayLike = ..., + construction_points: onp.ToFloatND = ..., use_dars: bool = ..., max_squeeze_hat_ratio: float = ..., random_state: Seed | None = ..., @@ -83,7 +82,7 @@ class TransformedDensityRejection(Method): @overload def ppf_hat(self, /, u: onp.ToFloat) -> float: ... @overload - def ppf_hat(self, /, u: npt.ArrayLike) -> float | onp.ArrayND[np.float64]: ... + def ppf_hat(self, /, u: onp.ToScalar | onp.ToArrayND) -> float | onp.ArrayND[np.float64]: ... class SimpleRatioUniforms(Method): def __init__( @@ -116,7 +115,7 @@ class NumericalInversePolynomial(_PPFMethodMixin, Method): @overload def cdf(self, /, x: onp.ToFloat) -> float: ... @overload - def cdf(self, /, x: npt.ArrayLike) -> float | onp.ArrayND[np.float64]: ... + def cdf(self, /, x: onp.ToFloat | onp.ToFloatND) -> float | onp.ArrayND[np.float64]: ... def u_error(self, /, sample_size: int = ...) -> UError: ... def qrvs( self, @@ -124,7 +123,7 @@ class NumericalInversePolynomial(_PPFMethodMixin, Method): size: int | tuple[int, ...] | None = ..., d: int | None = ..., qmc_engine: stats.qmc.QMCEngine | None = ..., - ) -> npt.ArrayLike: ... + ) -> float | onp.ArrayND[np.float64]: ... class NumericalInverseHermite(_PPFMethodMixin, Method): def __init__( @@ -135,7 +134,7 @@ class NumericalInverseHermite(_PPFMethodMixin, Method): domain: tuple[float, float] | None = ..., order: int = ..., u_resolution: float = ..., - construction_points: npt.ArrayLike | None = ..., + construction_points: onp.ToFloatND | None = ..., max_intervals: int = ..., random_state: Seed | None = ..., ) -> None: ... @@ -150,13 +149,13 @@ class NumericalInverseHermite(_PPFMethodMixin, Method): size: int | tuple[int, ...] | None = ..., d: int | None = ..., qmc_engine: stats.qmc.QMCEngine | None = ..., - ) -> npt.ArrayLike: ... + ) -> float | onp.ArrayND[np.float64]: ... class DiscreteAliasUrn(Method): def __init__( self, /, - dist: npt.ArrayLike | _HasPMF, + dist: onp.ToFloat | onp.ToFloatND | _HasPMF, *, domain: tuple[float, float] | None = ..., urn_factor: float = ..., @@ -167,7 +166,7 @@ class DiscreteGuideTable(_PPFMethodMixin, Method): def __init__( self, /, - dist: npt.ArrayLike | _HasPMF, + dist: onp.ToFloat | onp.ToFloatND | _HasPMF, *, domain: tuple[float, float] | None = ..., guide_factor: float = ..., diff --git a/scipy-stubs/stats/_variation.pyi b/scipy-stubs/stats/_variation.pyi index 9e34bce2..2b1933b7 100644 --- a/scipy-stubs/stats/_variation.pyi +++ b/scipy-stubs/stats/_variation.pyi @@ -3,7 +3,6 @@ from typing import Any, Literal, overload from typing_extensions import TypeVar import numpy as np -import numpy.typing as npt import optype as op import optype.numpy as onp from numpy._typing import _ArrayLike, _NestedSequence @@ -125,7 +124,7 @@ def variation( # catch-all in case of broad gradual types @overload def variation( - a: npt.ArrayLike, + a: onp.ToComplexND, axis: op.CanIndex | None = 0, nan_policy: NanPolicy = "propagate", ddof: onp.ToInt = 0,