diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3c72595..f5c4f625 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,18 +38,37 @@ jobs: - name: install run: poetry install - - name: lint (ruff) + - name: lint run: poe lint --output-format=github - name: typetest run: poe typetest - - name: verifytypes (basedpyright) + - name: verifytypes run: poe verifytypes + - name: typecheck (partial) + run: | + targets=( + "__init__.pyi" + "constants" + "datasets" + "integrate" + "io" + "linalg" + "misc" + "special" + "stats/distributions.pyi" + "version.pyi" + ) + for target in "${targets[@]}"; do + poe mypy $target + poe pyright $target + done + stubtest: needs: lint-and-typecheck - timeout-minutes: 10 + timeout-minutes: 5 runs-on: ubuntu-latest strategy: fail-fast: false @@ -63,8 +82,7 @@ jobs: "scipy.fftpack", "scipy.integrate", # "scipy.interpolate", - # "scipy.io", - "scipy.io.arff scipy.io.matlab", + "scipy.io", "scipy.linalg", "scipy.misc", # "scipy.ndimage", @@ -81,10 +99,7 @@ jobs: steps: - uses: actions/checkout@v4 - - run: | - pipx install poetry poethepoet - poetry config virtualenvs.create true --local - poetry config virtualenvs.in-project true --local + - run: pipx install poetry poethepoet - uses: actions/setup-python@v5 with: @@ -103,10 +118,7 @@ jobs: steps: - uses: actions/checkout@v4 - - run: | - pipx install poetry poethepoet - poetry config virtualenvs.create true --local - poetry config virtualenvs.in-project true --local + - run: pipx install poetry poethepoet - uses: actions/setup-python@v5 with: diff --git a/README.md b/README.md index b0b0ae25..bd00a546 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ The exact version requirements are specified in the [`pyproject.toml`](pyproject | `scipy.fftpack` | 3: ready | | `scipy.integrate` | **4: done** | | `scipy.interpolate` | 2: partial | -| `scipy.io` | 2: partial | +| `scipy.io` | **4: done** | | `scipy.io.arff` | 3: ready | | `scipy.io.matlab` | 3: ready | | `scipy.linalg` | **4: done** | diff --git a/pyproject.toml b/pyproject.toml index 1fcc6cd6..bd8b1695 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,11 +68,11 @@ args = [{name = "path", positional = true, multiple = true, default = ""}] [tool.poe.tasks.mypy] cmd = "mypy --config-file=pyproject.toml scipy-stubs/$path" -args = [{name = "path", positional = true, multiple = true, default = ""}] +args = [{name = "path", positional = true, multiple = false, default = ""}] [tool.poe.tasks.verifytypes] cmd = "basedpyright --ignoreexternal --verifytypes scipy-stubs/$path" -args = [{name = "path", positional = true, multiple = true, default = ""}] +args = [{name = "path", positional = true, multiple = false, default = ""}] [tool.poe.tasks.stubtest] cmd = """ @@ -95,8 +95,6 @@ warn_unused_ignores = true [tool.pyright] include = ["scipy-stubs", "typetests"] -exclude = [".cache"] -ignore = [".venv"] venv = ".venv" venvPath = "." stubPath = "." @@ -106,16 +104,16 @@ typeCheckingMode = "strict" deprecateTypingAliases = true enableTypeIgnoreComments = false +reportDeprecated = false reportIgnoreCommentWithoutRule = true reportImplicitRelativeImport = true reportInvalidCast = true reportPrivateUsage = false reportUnnecessaryTypeIgnoreComment = true -reportUnsafeMultipleInheritance = true [tool.ruff] builtins = ["reveal_locals", "reveal_type"] -exclude = ["scipy-pyright", ".venv"] +exclude = [".venv"] force-exclude = true target-version = "py310" # https://typing.readthedocs.io/en/latest/guides/writing_stubs.html#maximum-line-length diff --git a/scipy-stubs/_typing.pyi b/scipy-stubs/_typing.pyi index 3f322976..9382b9f5 100644 --- a/scipy-stubs/_typing.pyi +++ b/scipy-stubs/_typing.pyi @@ -1,6 +1,7 @@ # Helper types for internal use (type-check only). +from os import PathLike from collections.abc import Callable, Sequence -from typing import Any, Literal, Protocol, TypeAlias, type_check_only +from typing import IO, Any, Literal, Protocol, TypeAlias, type_check_only from typing_extensions import LiteralString, TypeVar import numpy as np @@ -17,8 +18,13 @@ __all__ = [ "AnyScalar", "AnyShape", "Array0D", + "ByteOrder", "Casting", "CorrelateMode", + "FileLike", + "FileModeRW", + "FileModeRWA", + "FileName", "NanPolicy", "Seed", "Untyped", @@ -38,6 +44,13 @@ UntypedDict: TypeAlias = dict[Untyped, Untyped] UntypedCallable: TypeAlias = Callable[..., Untyped] UntypedArray: TypeAlias = onpt.Array[tuple[int, ...], np.generic] +# I/O +_ByteSOrStr = TypeVar("_ByteSOrStr", bytes, str) +FileName: TypeAlias = str | PathLike[str] +FileLike: TypeAlias = IO[_ByteSOrStr] | FileName +FileModeRW: TypeAlias = Literal["r", "w"] +FileModeRWA: TypeAlias = Literal[FileModeRW, "a"] + _SCT = TypeVar("_SCT", bound=np.generic, default=np.generic) Array0D: TypeAlias = np.ndarray[tuple[()], np.dtype[_SCT]] @@ -55,6 +68,7 @@ AnyShape: TypeAlias = op.CanIndex | Sequence[op.CanIndex] # numpy literals RNG: TypeAlias = np.random.Generator | np.random.RandomState Seed: TypeAlias = int | RNG +ByteOrder: TypeAlias = Literal["S", "<", "little", ">", "big", "=", "native", "|", "I"] Casting: TypeAlias = Literal["no", "equiv", "safe", "same_kind", "unsafe"] CorrelateMode: TypeAlias = Literal["valid", "same", "full"] diff --git a/scipy-stubs/io/__init__.pyi b/scipy-stubs/io/__init__.pyi index 55609aa0..4a6fc925 100644 --- a/scipy-stubs/io/__init__.pyi +++ b/scipy-stubs/io/__init__.pyi @@ -1,11 +1,31 @@ -from . import arff as arff, harwell_boeing as harwell_boeing, idl as idl, mmio as mmio, netcdf as netcdf, wavfile as wavfile -from ._fast_matrix_market import mminfo as mminfo, mmread as mmread, mmwrite as mmwrite -from ._fortran import ( - FortranEOFError as FortranEOFError, - FortranFile as FortranFile, - FortranFormattingError as FortranFormattingError, -) -from ._harwell_boeing import hb_read as hb_read, hb_write as hb_write -from ._idl import readsav as readsav -from ._netcdf import netcdf_file as netcdf_file, netcdf_variable as netcdf_variable -from .matlab import loadmat as loadmat, savemat as savemat, whosmat as whosmat +from . import arff, harwell_boeing, idl, matlab, mmio, netcdf, wavfile +from ._fast_matrix_market import mminfo, mmread, mmwrite +from ._fortran import FortranEOFError, FortranFile, FortranFormattingError +from ._harwell_boeing import hb_read, hb_write +from ._idl import readsav +from ._netcdf import netcdf_file, netcdf_variable +from .matlab import loadmat, savemat, whosmat + +__all__ = [ + "FortranEOFError", + "FortranFile", + "FortranFormattingError", + "arff", + "harwell_boeing", + "hb_read", + "hb_write", + "idl", + "loadmat", + "matlab", + "mminfo", + "mmio", + "mmread", + "mmwrite", + "netcdf", + "netcdf_file", + "netcdf_variable", + "readsav", + "savemat", + "wavfile", + "whosmat", +] diff --git a/scipy-stubs/io/_fast_matrix_market/__init__.pyi b/scipy-stubs/io/_fast_matrix_market/__init__.pyi index 152153dc..1aa7527f 100644 --- a/scipy-stubs/io/_fast_matrix_market/__init__.pyi +++ b/scipy-stubs/io/_fast_matrix_market/__init__.pyi @@ -1,27 +1,53 @@ import io -from typing_extensions import override +from typing import Final, Literal, TypeAlias, type_check_only +from typing_extensions import TypedDict, Unpack, override -from scipy._typing import Untyped +import numpy as np +import numpy.typing as npt +import optype.numpy as onpt +from scipy._typing import FileName +from scipy.sparse import coo_matrix, sparray, spmatrix __all__ = ["mminfo", "mmread", "mmwrite"] -PARALLELISM: int -ALWAYS_FIND_SYMMETRY: bool +_Format: TypeAlias = Literal["coordinate", "array"] +_Field: TypeAlias = Literal["real", "complex", "pattern", "integer"] +_Symmetry: TypeAlias = Literal["general", "symmetric", "skew-symmetric", "hermitian"] + +PARALLELISM: Final = 0 +ALWAYS_FIND_SYMMETRY: Final = False + +@type_check_only +class _TextToBytesWrapperKwargs(TypedDict, total=False): + buffer_size: int class _TextToBytesWrapper(io.BufferedReader): - encoding: Untyped - errors: Untyped - def __init__(self, text_io_buffer, encoding: Untyped | None = None, errors: Untyped | None = None, **kwargs): ... + encoding: Final[str] + errors: Final[str] + def __init__( + self, + /, + text_io_buffer: io.TextIOBase, + encoding: str | None = None, + errors: str | None = None, + **kwargs: Unpack[_TextToBytesWrapperKwargs], + ) -> None: ... + @override + def read(self, /, size: int | None = -1) -> bytes: ... + @override + def read1(self, /, size: int = -1) -> bytes: ... + @override + def peek(self, /, size: int = -1) -> bytes: ... @override - def seek(self, offset: int, whence: int = 0, /) -> None: ... # type: ignore[override] + def seek(self, /, offset: int, whence: int = 0) -> None: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] -def mmread(source) -> Untyped: ... +def mmread(source: FileName) -> npt.NDArray[np.generic] | coo_matrix: ... def mmwrite( - target, - a, - comment: Untyped | None = None, - field: Untyped | None = None, - precision: Untyped | None = None, - symmetry: str = "AUTO", -): ... -def mminfo(source) -> Untyped: ... + target: FileName, + a: onpt.CanArray | list[object] | tuple[object, ...] | sparray | spmatrix, + comment: str | None = None, + field: _Field | None = None, + precision: int | None = None, + symmetry: _Symmetry | Literal["AUTO"] = "AUTO", +) -> None: ... +def mminfo(source: FileName) -> tuple[int, int, int, _Format, _Field, _Symmetry]: ... diff --git a/scipy-stubs/io/_fortran.pyi b/scipy-stubs/io/_fortran.pyi index fdbc8232..3d5280ec 100644 --- a/scipy-stubs/io/_fortran.pyi +++ b/scipy-stubs/io/_fortran.pyi @@ -1,16 +1,41 @@ from types import TracebackType +from typing import Any, TypedDict, final, overload, type_check_only +from typing_extensions import Self, Unpack -from scipy._typing import Untyped +import numpy as np +import numpy.typing as npt +import optype.numpy as onpt +from scipy._typing import FileLike, FileModeRW + +__all__ = ["FortranEOFError", "FortranFile", "FortranFormattingError"] + +@type_check_only +@final +class _DTypeKwargs(TypedDict): + dtype: npt.DTypeLike class FortranEOFError(TypeError, OSError): ... class FortranFormattingError(TypeError, OSError): ... class FortranFile: - def __init__(self, filename, mode: str = "r", header_dtype=...): ... - def write_record(self, *items): ... - def read_record(self, *dtypes, **kwargs) -> Untyped: ... - def read_ints(self, dtype: str = "i4") -> Untyped: ... - def read_reals(self, dtype: str = "f8") -> Untyped: ... - def close(self): ... - def __enter__(self) -> Untyped: ... - def __exit__(self, type: type[BaseException] | None, value: BaseException | None, tb: TracebackType | None): ... + def __init__(self, /, filename: FileLike[bytes], mode: FileModeRW = "r", header_dtype: npt.DTypeLike = ...) -> None: ... + def __enter__(self, /) -> Self: ... + def __exit__(self, /, type: type[BaseException] | None, value: BaseException | None, tb: TracebackType | None) -> None: ... + def close(self, /) -> None: ... + def write_record(self, /, *items: npt.ArrayLike) -> None: ... + @overload + def read_record(self, /, *dtypes: npt.DTypeLike) -> onpt.Array[tuple[int], np.void]: ... + @overload + def read_record(self, /, *dtypes: npt.DTypeLike, **kwargs: Unpack[_DTypeKwargs]) -> onpt.Array[tuple[int], np.void]: ... + @overload + def read_ints(self, /) -> onpt.Array[tuple[int], np.int32]: ... + @overload + def read_ints(self, /, dtype: onpt.AnyIntegerDType) -> onpt.Array[tuple[int], np.integer[Any]]: ... + @overload + def read_ints(self, /, dtype: npt.DTypeLike) -> onpt.Array[tuple[int]]: ... + @overload + def read_reals(self, /) -> onpt.Array[tuple[int], np.float64]: ... + @overload + def read_reals(self, /, dtype: onpt.AnyFloatingDType) -> onpt.Array[tuple[int], np.floating[Any]]: ... + @overload + def read_reals(self, /, dtype: npt.DTypeLike) -> onpt.Array[tuple[int]]: ... diff --git a/scipy-stubs/io/_harwell_boeing/_fortran_format_parser.pyi b/scipy-stubs/io/_harwell_boeing/_fortran_format_parser.pyi index aa4ad997..9d9dff9a 100644 --- a/scipy-stubs/io/_harwell_boeing/_fortran_format_parser.pyi +++ b/scipy-stubs/io/_harwell_boeing/_fortran_format_parser.pyi @@ -1,53 +1,55 @@ -from scipy._typing import Untyped +import abc +import re +from typing import Final, Generic, Literal, TypeAlias, TypeVar, type_check_only +from typing_extensions import Self -TOKENS: Untyped +import scipy._typing as spt -class BadFortranFormat(SyntaxError): ... +__all__ = ["BadFortranFormat", "ExpFormat", "FortranFormatParser", "IntFormat"] -def number_digits(n) -> Untyped: ... +_NumberT = TypeVar("_NumberT", int, float) +_TokenType: TypeAlias = Literal["INT", "INT_ID", "EXP_ID", "DOT", "LPAR", "RPAR"] -class IntFormat: - @classmethod - def from_number(cls, n, min: Untyped | None = None) -> Untyped: ... - width: Untyped - repeat: Untyped - min: Untyped - def __init__(self, width, min: Untyped | None = None, repeat: Untyped | None = None): ... - @property - def fortran_format(self) -> Untyped: ... - @property - def python_format(self) -> Untyped: ... +TOKENS: Final[dict[_TokenType, str]] -class ExpFormat: - @classmethod - def from_number(cls, n, min: Untyped | None = None) -> Untyped: ... - width: Untyped - significand: Untyped - repeat: Untyped - min: Untyped - def __init__(self, width, significand, min: Untyped | None = None, repeat: Untyped | None = None): ... +class BadFortranFormat(SyntaxError): ... + +@type_check_only +class _NumberFormat(Generic[_NumberT], metaclass=abc.ABCMeta): + width: Final[int] + repeat: Final[int | None] + min: Final[int | None] @property - def fortran_format(self) -> Untyped: ... + def fortran_format(self, /) -> str: ... @property - def python_format(self) -> Untyped: ... + def python_format(self, /) -> str: ... + @classmethod + def from_number(cls, n: _NumberT, min: int | None = None) -> Self: ... + +class IntFormat(_NumberFormat[int]): + def __init__(self, /, width: int, min: int | None = None, repeat: int | None = None) -> None: ... + +class ExpFormat(_NumberFormat[float]): + significand: Final[int] + def __init__(self, /, width: int, significand: int, min: int | None = None, repeat: int | None = None) -> None: ... class Token: - type: Untyped - value: Untyped - pos: Untyped - def __init__(self, type, value, pos) -> None: ... + type: Final[_TokenType] + value: Final[str] + pos: Final[int] + def __init__(self, /, type: _TokenType, value: str, pos: int) -> None: ... class Tokenizer: - tokens: Untyped - res: Untyped - def __init__(self) -> None: ... - data: Untyped + tokens: Final[list[_TokenType]] + res: Final[list[re.Pattern[str]]] + data: str curpos: int - len: Untyped - def input(self, s): ... - def next_token(self) -> Untyped: ... + len: int + def input(self, /, s: str) -> None: ... + def next_token(self, /) -> Token: ... class FortranFormatParser: - tokenizer: Untyped - def __init__(self) -> None: ... - def parse(self, s) -> Untyped: ... + tokenizer: Final[Tokenizer] + def parse(self, /, s: str) -> IntFormat | ExpFormat: ... + +def number_digits(n: spt.AnyInt) -> int: ... diff --git a/scipy-stubs/io/_harwell_boeing/hb.pyi b/scipy-stubs/io/_harwell_boeing/hb.pyi index 89ffeeae..02e6b87c 100644 --- a/scipy-stubs/io/_harwell_boeing/hb.pyi +++ b/scipy-stubs/io/_harwell_boeing/hb.pyi @@ -1,81 +1,97 @@ -from scipy._typing import Untyped -from scipy.sparse import csc_matrix as csc_matrix -from ._fortran_format_parser import ExpFormat as ExpFormat, FortranFormatParser as FortranFormatParser, IntFormat as IntFormat +import io +from typing import Final, Literal, TypeAlias +from typing_extensions import LiteralString, Self + +from scipy._typing import FileName, Untyped +from scipy.sparse import csc_matrix, sparray, spmatrix + +__all__ = ["hb_read", "hb_write"] + +_ValueType: TypeAlias = Literal["real", "complex", "pattern", "integer"] +_Structure: TypeAlias = Literal["symmetric", "unsymmetric", "hermitian", "skewsymmetric", "rectangular"] +_Storage: TypeAlias = Literal["assembled", "elemental"] class MalformedHeader(Exception): ... class LineOverflow(Warning): ... class HBInfo: + title: Final[str] + key: Final[str] + total_nlines: Final[int] + pointer_nlines: Final[int] + indices_nlines: Final[int] + values_nlines: Final[int] + pointer_format: Final[int] + indices_format: Final[int] + values_format: Final[int] + pointer_dtype: Final[int] + indices_dtype: Final[int] + values_dtype: Final[int] + pointer_nbytes_full: Final[int] + indices_nbytes_full: Final[int] + values_nbytes_full: Final[int] + nrows: Final[int] + ncols: Final[int] + nnon_zeros: Final[int] + nelementals: Final[int] + mxtype: HBMatrixType + @classmethod def from_data( - cls, m, title: str = "Default title", key: str = "0", mxtype: Untyped | None = None, fmt: Untyped | None = None - ) -> Untyped: ... + cls, + m: sparray | spmatrix, + title: str = "Default title", + key: str = "0", + mxtype: HBMatrixType | None = None, + fmt: None = None, + ) -> Self: ... @classmethod - def from_file(cls, fid) -> Untyped: ... - title: Untyped - key: Untyped - total_nlines: Untyped - pointer_nlines: Untyped - indices_nlines: Untyped - values_nlines: Untyped - pointer_format: Untyped - indices_format: Untyped - values_format: Untyped - pointer_dtype: Untyped - indices_dtype: Untyped - values_dtype: Untyped - pointer_nbytes_full: Untyped - indices_nbytes_full: Untyped - values_nbytes_full: Untyped - nrows: Untyped - ncols: Untyped - nnon_zeros: Untyped - nelementals: Untyped - mxtype: Untyped + def from_file(cls, fid: io.IOBase) -> Self: ... def __init__( self, - title, - key, - total_nlines, - pointer_nlines, - indices_nlines, - values_nlines, - mxtype, - nrows, - ncols, - nnon_zeros, - pointer_format_str, - indices_format_str, - values_format_str, + /, + title: str, + key: str, + total_nlines: int, + pointer_nlines: int, + indices_nlines: int, + values_nlines: int, + mxtype: HBMatrixType, + nrows: int, + ncols: int, + nnon_zeros: int, + pointer_format_str: str, + indices_format_str: str, + values_format_str: str, right_hand_sides_nlines: int = 0, nelementals: int = 0, - ): ... - def dump(self) -> Untyped: ... + ) -> None: ... + def dump(self, /) -> str: ... class HBMatrixType: + value_type: Final[_ValueType] + structure: Final[_Structure] + storage: Final[_Storage] @classmethod - def from_fortran(cls, fmt) -> Untyped: ... - value_type: Untyped - structure: Untyped - storage: Untyped - def __init__(self, value_type, structure, storage: str = "assembled"): ... + def from_fortran(cls, fmt: str) -> Self: ... + def __init__(self, /, value_type: _ValueType, structure: _Structure, storage: _Storage = "assembled") -> None: ... @property - def fortran_format(self) -> Untyped: ... + def fortran_format(self, /) -> LiteralString: ... class HBFile: - def __init__(self, file, hb_info: Untyped | None = None): ... + def __init__(self, /, file: io.IOBase, hb_info: HBMatrixType | None = None) -> None: ... @property - def title(self) -> Untyped: ... + def title(self, /) -> str: ... @property - def key(self) -> Untyped: ... + def key(self, /) -> str: ... @property - def type(self) -> Untyped: ... + def type(self, /) -> _ValueType: ... @property - def structure(self) -> Untyped: ... + def structure(self, /) -> _Structure: ... @property - def storage(self) -> Untyped: ... - def read_matrix(self) -> Untyped: ... - def write_matrix(self, m) -> Untyped: ... + def storage(self, /) -> _Storage: ... + def read_matrix(self, /) -> csc_matrix: ... + def write_matrix(self, /, m: spmatrix | sparray) -> Untyped: ... -def hb_read(path_or_open_file) -> Untyped: ... -def hb_write(path_or_open_file, m, hb_info: Untyped | None = None) -> Untyped: ... +def hb_read(path_or_open_file: io.IOBase | FileName) -> csc_matrix: ... +def hb_write(path_or_open_file: io.IOBase | FileName, m: spmatrix | sparray, hb_info: HBInfo | None = None) -> None: ... diff --git a/scipy-stubs/io/_idl.pyi b/scipy-stubs/io/_idl.pyi index defb156d..8c64ee28 100644 --- a/scipy-stubs/io/_idl.pyi +++ b/scipy-stubs/io/_idl.pyi @@ -1,21 +1,29 @@ -from typing import Any +from os import PathLike +from typing import Final, Generic +from typing_extensions import TypeVar __all__ = ["readsav"] +_VT = TypeVar("_VT", default=object) + +DTYPE_DICT: Final[dict[int, str]] = ... +RECTYPE_DICT: Final[dict[int, str]] = ... +STRUCT_DICT: Final[dict[str, dict[str, object]]] = ... + class Pointer: index: int - def __init__(self, index: int) -> None: ... + def __init__(self, /, index: int) -> None: ... class ObjectPointer(Pointer): ... -class AttrDict(dict[str, Any]): - def __init__(self, /, init: dict[str, Any] = ...) -> None: ... - def __call__(self, name: str, /) -> Any: ... +class AttrDict(dict[str, _VT], Generic[_VT]): + def __init__(self, /, init: dict[str, object] = ...) -> None: ... + def __call__(self, /, name: str) -> object: ... def readsav( - file_name: str, - idict: dict[str, Any] | None = None, + file_name: str | bytes | PathLike[str] | PathLike[bytes], + idict: dict[str, object] | None = None, python_dict: bool = False, uncompressed_file_name: str | None = None, verbose: bool = False, -) -> dict[str, Any]: ... +) -> AttrDict[object] | dict[str, object]: ... diff --git a/scipy-stubs/io/_mmio.pyi b/scipy-stubs/io/_mmio.pyi index fab7ec4e..9ef6bd85 100644 --- a/scipy-stubs/io/_mmio.pyi +++ b/scipy-stubs/io/_mmio.pyi @@ -1,57 +1,88 @@ -from scipy._typing import Untyped -from scipy.sparse import coo_matrix as coo_matrix, issparse as issparse +from typing import Any, ClassVar, Literal, TypeAlias, TypedDict, type_check_only +from typing_extensions import Unpack -def asstr(s) -> Untyped: ... -def mminfo(source) -> Untyped: ... -def mmread(source) -> Untyped: ... +import numpy as np +import numpy.typing as npt +from scipy._typing import FileLike +from scipy.sparse import coo_matrix, sparray, spmatrix + +__all__ = ["MMFile", "mminfo", "mmread", "mmwrite"] + +_Format: TypeAlias = Literal["coordinate", "array"] +_Field: TypeAlias = Literal["real", "complex", "pattern", "integer"] +_Symmetry: TypeAlias = Literal["general", "symmetric", "skew-symmetric", "hermitian"] +_Info: TypeAlias = tuple[int, int, int, _Format, _Field, _Symmetry] + +@type_check_only +class _MMFileKwargs(TypedDict, total=False): + rows: int + cols: int + entries: int + format: _Format + field: _Field + symmetry: _Symmetry + +def asstr(s: object) -> str: ... +def mminfo(source: FileLike[bytes]) -> _Info: ... +def mmread(source: FileLike[bytes]) -> npt.NDArray[np.number[Any]] | coo_matrix: ... def mmwrite( - target, a, comment: str = "", field: Untyped | None = None, precision: Untyped | None = None, symmetry: Untyped | None = None -): ... + target: FileLike[bytes], + a: spmatrix | sparray | npt.ArrayLike, + comment: str = "", + field: _Field | None = None, + precision: int | None = None, + symmetry: _Symmetry | None = None, +) -> None: ... class MMFile: + FORMAT_COORDINATE: ClassVar = "coordinate" + FORMAT_ARRAY: ClassVar = "array" + FORMAT_VALUES: ClassVar = "coordinate", "array" + + FIELD_INTEGER: ClassVar = "integer" + FIELD_UNSIGNED: ClassVar = "unsigned-integer" + FIELD_REAL: ClassVar = "real" + FIELD_COMPLEX: ClassVar = "complex" + FIELD_PATTERN: ClassVar = "pattern" + FIELD_VALUES: ClassVar = "integer", "unsigned-integer", "real", "complex", "pattern" + + SYMMETRY_GENERAL: ClassVar = "general" + SYMMETRY_SYMMETRIC: ClassVar = "symmetric" + SYMMETRY_SKEW_SYMMETRIC: ClassVar = "skew-symmetric" + SYMMETRY_HERMITIAN: ClassVar = "hermitian" + SYMMETRY_VALUES: ClassVar = "general", "symmetric", "skew-symmetric", "hermitian" + + DTYPES_BY_FIELD: ClassVar[dict[_Field, Literal["intp", "uint64", "d", "D"]]] = ... + + def __init__(self, /, **kwargs: Unpack[_MMFileKwargs]) -> None: ... @property - def rows(self) -> Untyped: ... + def rows(self, /) -> int: ... @property - def cols(self) -> Untyped: ... + def cols(self, /) -> int: ... @property - def entries(self) -> Untyped: ... + def entries(self, /) -> int: ... @property - def format(self) -> Untyped: ... + def format(self, /) -> _Format: ... @property - def field(self) -> Untyped: ... + def field(self, /) -> _Field: ... @property - def symmetry(self) -> Untyped: ... + def symmetry(self, /) -> _Symmetry: ... @property - def has_symmetry(self) -> Untyped: ... - FORMAT_COORDINATE: str - FORMAT_ARRAY: str - FORMAT_VALUES: Untyped - FIELD_INTEGER: str - FIELD_UNSIGNED: str - FIELD_REAL: str - FIELD_COMPLEX: str - FIELD_PATTERN: str - FIELD_VALUES: Untyped - SYMMETRY_GENERAL: str - SYMMETRY_SYMMETRIC: str - SYMMETRY_SKEW_SYMMETRIC: str - SYMMETRY_HERMITIAN: str - SYMMETRY_VALUES: Untyped - DTYPES_BY_FIELD: Untyped - @staticmethod - def reader(): ... - @staticmethod - def writer(): ... - @classmethod - def info(cls, /, source) -> Untyped: ... - def __init__(self, **kwargs) -> None: ... - def read(self, source) -> Untyped: ... + def has_symmetry(self, /) -> bool: ... + def read(self, /, source: FileLike[bytes]) -> npt.NDArray[np.number[Any]] | coo_matrix: ... def write( self, - target, - a, + /, + target: FileLike[bytes], + a: spmatrix | sparray | npt.ArrayLike, comment: str = "", - field: Untyped | None = None, - precision: Untyped | None = None, - symmetry: Untyped | None = None, - ): ... + field: _Field | None = None, + precision: int | None = None, + symmetry: _Symmetry | None = None, + ) -> None: ... + @classmethod + def info(cls, /, source: FileLike[bytes]) -> _Info: ... + @staticmethod + def reader() -> None: ... + @staticmethod + def writer() -> None: ... diff --git a/scipy-stubs/io/_netcdf.pyi b/scipy-stubs/io/_netcdf.pyi index ab62f980..c4b7e4bd 100644 --- a/scipy-stubs/io/_netcdf.pyi +++ b/scipy-stubs/io/_netcdf.pyi @@ -1,74 +1,95 @@ +from collections.abc import Sequence from types import TracebackType +from typing import IO, Final +from typing_extensions import Self -from scipy._typing import Untyped +import numpy.typing as npt +from scipy._typing import FileLike, FileModeRWA, Untyped -IS_PYPY: Untyped -ABSENT: bytes -ZERO: bytes -NC_BYTE: bytes -NC_CHAR: bytes -NC_SHORT: bytes -NC_INT: bytes -NC_FLOAT: bytes -NC_DOUBLE: bytes -NC_DIMENSION: bytes -NC_VARIABLE: bytes -NC_ATTRIBUTE: bytes -FILL_BYTE: bytes -FILL_CHAR: bytes -FILL_SHORT: bytes -FILL_INT: bytes -FILL_FLOAT: bytes -FILL_DOUBLE: bytes -TYPEMAP: Untyped -FILLMAP: Untyped -REVERSE: Untyped +__all__ = ["netcdf_file", "netcdf_variable"] + +IS_PYPY: Final[bool] = ... + +ABSENT: Final[bytes] = ... +ZERO: Final[bytes] = ... +NC_BYTE: Final[bytes] = ... +NC_CHAR: Final[bytes] = ... +NC_SHORT: Final[bytes] = ... +NC_INT: Final[bytes] = ... +NC_FLOAT: Final[bytes] = ... +NC_DOUBLE: Final[bytes] = ... +NC_DIMENSION: Final[bytes] = ... +NC_VARIABLE: Final[bytes] = ... +NC_ATTRIBUTE: Final[bytes] = ... +FILL_BYTE: Final[bytes] = ... +FILL_CHAR: Final[bytes] = ... +FILL_SHORT: Final[bytes] = ... +FILL_INT: Final[bytes] = ... +FILL_FLOAT: Final[bytes] = ... +FILL_DOUBLE: Final[bytes] = ... + +TYPEMAP: Final[dict[bytes, tuple[str, int]]] +FILLMAP: Final[dict[bytes, bytes]] +REVERSE: Final[dict[tuple[str, int], bytes]] class netcdf_file: - fp: Untyped + fp: IO[bytes] filename: str - use_mmap: Untyped - mode: Untyped - version_byte: Untyped + use_mmap: bool + mode: FileModeRWA + version_byte: int maskandscale: Untyped - dimensions: Untyped - variables: Untyped - def __init__(self, filename, mode: str = "r", mmap: Untyped | None = None, version: int = 1, maskandscale: bool = False): ... - def __setattr__(self, attr, value) -> None: ... - def close(self): ... - __del__ = close - def __enter__(self) -> Untyped: ... - def __exit__(self, type: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None): ... - def createDimension(self, name, length): ... - def createVariable(self, name, type, dimensions) -> Untyped: ... - def flush(self): ... - sync = flush + dimensions: dict[str, int] + variables: dict[str, netcdf_variable] + def __init__( + self, + /, + filename: FileLike[bytes], + mode: FileModeRWA = "r", + mmap: bool | None = None, + version: int = 1, + maskandscale: bool = False, + ) -> None: ... + def __del__(self, /) -> None: ... + def __enter__(self, /) -> Self: ... + def __exit__( + self, + /, + type: type[BaseException] | None, + value: BaseException | None, + traceback: TracebackType | None, + ) -> None: ... + def close(self, /) -> None: ... + def createDimension(self, /, name: str, length: int) -> None: ... + def createVariable(self, /, name: str, type: npt.DTypeLike, dimensions: Sequence[str]) -> netcdf_variable: ... + def flush(self, /) -> None: ... + def sync(self, /) -> None: ... class netcdf_variable: - data: Untyped - dimensions: Untyped - maskandscale: Untyped + data: npt.ArrayLike + dimensions: Sequence[str] + maskandscale: bool @property - def isrec(self) -> Untyped: ... + def isrec(self, /) -> Untyped: ... @property - def shape(self) -> Untyped: ... + def shape(self, /) -> Untyped: ... def __init__( self, - data, - typecode, - size, - shape, - dimensions, - attributes: Untyped | None = None, + /, + data: npt.ArrayLike, + typecode: str, + size: int, + shape: Sequence[int], + dimensions: Sequence[str], + attributes: dict[str, object] | None = None, maskandscale: bool = False, - ): ... - def __setattr__(self, attr, value) -> None: ... - def getValue(self) -> Untyped: ... - def assignValue(self, value): ... - def typecode(self) -> Untyped: ... - def itemsize(self) -> Untyped: ... - def __getitem__(self, index) -> Untyped: ... - def __setitem__(self, index, data) -> None: ... + ) -> None: ... + def __getitem__(self, /, index: object) -> object: ... + def __setitem__(self, /, index: object, data: npt.ArrayLike) -> None: ... + def getValue(self, /) -> object: ... + def assignValue(self, /, value: object) -> None: ... + def typecode(self, /) -> str: ... + def itemsize(self, /) -> int: ... NetCDFFile = netcdf_file NetCDFVariable = netcdf_variable diff --git a/scipy-stubs/io/arff/_arffread.pyi b/scipy-stubs/io/arff/_arffread.pyi index 2a323e2a..7252f0f2 100644 --- a/scipy-stubs/io/arff/_arffread.pyi +++ b/scipy-stubs/io/arff/_arffread.pyi @@ -1,96 +1,100 @@ -from scipy._typing import Untyped +import abc +import re +from csv import Dialect +from collections.abc import Iterable, Iterator, Sequence +from typing import Any, ClassVar, Final, Generic, Literal +from typing_extensions import Self, TypeVar + +import numpy as np +import numpy.typing as npt +from scipy._typing import FileLike, FileName __all__ = ["ArffError", "MetaData", "ParseArffError", "loadarff"] -r_meta: Untyped -r_comment: Untyped -r_empty: Untyped -r_headerline: Untyped -r_datameta: Untyped -r_relation: Untyped -r_attribute: Untyped -r_nominal: Untyped -r_date: Untyped -r_comattrval: Untyped -r_wcomattrval: Untyped +_T_co = TypeVar("_T_co", covariant=True, default=object) + +r_meta: re.Pattern[str] +r_comment: re.Pattern[str] +r_empty: re.Pattern[str] +r_headerline: re.Pattern[str] +r_datameta: re.Pattern[str] +r_relation: re.Pattern[str] +r_attribute: re.Pattern[str] +r_nominal: re.Pattern[str] +r_date: re.Pattern[str] +r_comattrval: re.Pattern[str] +r_wcomattrval: re.Pattern[str] class ArffError(OSError): ... class ParseArffError(ArffError): ... -class Attribute: - type_name: str | None - name: Untyped - range: Untyped - dtype: Untyped - def __init__(self, name) -> None: ... - @classmethod - def parse_attribute(cls, name, attr_string): ... - def parse_data(self, data_str): ... - -class NominalAttribute(Attribute): - type_name: str | None - values: Untyped - range: Untyped - dtype: Untyped - def __init__(self, name, values) -> None: ... - @classmethod - def parse_attribute(cls, name, attr_string) -> Untyped: ... - def parse_data(self, data_str) -> Untyped: ... +class Attribute(Generic[_T_co], metaclass=abc.ABCMeta): + type_name: ClassVar[Any] + dtype: Any + range: Any -class NumericAttribute(Attribute): - type_name: str | None - dtype: Untyped - def __init__(self, name) -> None: ... - @classmethod - def parse_attribute(cls, name, attr_string) -> Untyped: ... - def parse_data(self, data_str) -> Untyped: ... + name: Final[str] -class StringAttribute(Attribute): - type_name: str | None - def __init__(self, name) -> None: ... + def __init__(self, /, name: str) -> None: ... @classmethod - def parse_attribute(cls, name, attr_string) -> Untyped: ... - -class DateAttribute(Attribute): - type_name: str | None - date_format: Untyped - datetime_unit: Untyped - range: Untyped - dtype: Untyped - def __init__(self, name, date_format, datetime_unit) -> None: ... - @classmethod - def parse_attribute(cls, name, attr_string) -> Untyped: ... - def parse_data(self, data_str) -> Untyped: ... - -class RelationalAttribute(Attribute): - type_name: str | None - dtype: Untyped - attributes: Untyped - dialect: Untyped - def __init__(self, name) -> None: ... - @classmethod - def parse_attribute(cls, name, attr_string) -> Untyped: ... - def parse_data(self, data_str) -> Untyped: ... - -def to_attribute(name, attr_string) -> Untyped: ... -def csv_sniffer_has_bug_last_field() -> Untyped: ... -def workaround_csv_sniffer_bug_last_field(sniff_line, dialect, delimiters): ... -def split_data_line(line, dialect: Untyped | None = None) -> Untyped: ... -def tokenize_attribute(iterable, attribute) -> Untyped: ... -def tokenize_single_comma(val) -> Untyped: ... -def tokenize_single_wcomma(val) -> Untyped: ... -def read_relational_attribute(ofile, relational_attribute, i) -> Untyped: ... -def read_header(ofile) -> Untyped: ... + def parse_attribute(cls, name: str, attr_string: str) -> Self | None: ... + def parse_data(self, /, data_str: str) -> _T_co: ... + +class NominalAttribute(Attribute[str]): + type_name: ClassVar = "nominal" + dtype: tuple[type[np.bytes_], ...] + range: Sequence[str] + + values: Final[Sequence[str]] + + def __init__(self, /, name: str, values: Sequence[str]) -> None: ... + +class NumericAttribute(Attribute[float]): + type_name: ClassVar = "numeric" + dtype: type[np.float64] + range: None + +class StringAttribute(Attribute[None]): + type_name: ClassVar = "string" + dtype: type[np.object_] + range: None + +class DateAttribute(Attribute[np.datetime64]): + type_name: ClassVar = "date" + dtype: np.datetime64 + range: str + + date_format: Final[str] + datetime_unit: Final[str] + + def __init__(self, /, name: str, date_format: str, datetime_unit: str) -> None: ... + +class RelationalAttribute(Attribute[np.ndarray[tuple[int], np.dtypes.VoidDType[int]]]): + type_name: ClassVar = "relational" + dtype: type[np.object_] + range: None + + attributes: Final[list[Attribute]] + dialect: Dialect | None class MetaData: - name: Untyped - def __init__(self, rel, attr) -> None: ... - def __iter__(self) -> Untyped: ... - def __getitem__(self, key) -> Untyped: ... - def names(self) -> Untyped: ... - def types(self) -> Untyped: ... - -def loadarff(f) -> Untyped: ... -def basic_stats(data) -> Untyped: ... -def print_attribute(name, tp, data): ... -def test_weka(filename): ... + name: Final[str] + def __init__(self, /, rel: str, attr: Iterable[Attribute]) -> None: ... + def __iter__(self, /) -> Iterator[str]: ... + def __getitem__(self, /, key: str) -> tuple[str, str | Sequence[str] | None]: ... + def names(self, /) -> list[str]: ... + def types(self, /) -> list[str]: ... + +def to_attribute(name: str, attr_string: str) -> Attribute: ... +def csv_sniffer_has_bug_last_field() -> Literal[False]: ... +def workaround_csv_sniffer_bug_last_field(sniff_line: str, dialect: Dialect, delimiters: Iterable[str]) -> None: ... +def split_data_line(line: str, dialect: Dialect | None = None) -> tuple[list[str], Dialect]: ... +def tokenize_attribute(iterable: Iterable[int | str], attribute: str) -> tuple[Attribute, object]: ... +def tokenize_single_comma(val: str) -> tuple[str, str]: ... +def tokenize_single_wcomma(val: str) -> tuple[str, str]: ... +def read_relational_attribute(ofile: Iterator[str], relational_attribute: RelationalAttribute, i: str) -> str: ... +def read_header(ofile: Iterator[str]) -> tuple[str, list[Attribute]]: ... +def loadarff(f: FileLike[str]) -> tuple[npt.NDArray[np.void], MetaData]: ... +def basic_stats(data: npt.NDArray[np.number[Any]]) -> tuple[np.number[Any], np.number[Any], np.number[Any], np.number[Any]]: ... +def print_attribute(name: str, tp: Attribute, data: Any) -> None: ... +def test_weka(filename: FileName) -> None: ... diff --git a/scipy-stubs/io/arff/arffread.pyi b/scipy-stubs/io/arff/arffread.pyi index 3bee6c82..c6c01487 100644 --- a/scipy-stubs/io/arff/arffread.pyi +++ b/scipy-stubs/io/arff/arffread.pyi @@ -1,21 +1,22 @@ # This module is not meant for public use and will be removed in SciPy v2.0.0. + from typing_extensions import deprecated __all__ = ["ArffError", "MetaData", "ParseArffError", "loadarff"] @deprecated("will be removed in SciPy v2.0.0") -class ArffError: ... +class ArffError(OSError): ... @deprecated("will be removed in SciPy v2.0.0") -class MetaData: - def __init__(self, rel: object, attr: object) -> None: ... - def __getitem__(self, key: object) -> object: ... - def __iter__(self) -> object: ... - def names(self) -> object: ... - def types(self) -> object: ... +class ParseArffError(ArffError): ... @deprecated("will be removed in SciPy v2.0.0") -class ParseArffError: ... +class MetaData: + def __init__(self, /, rel: object, attr: object) -> None: ... + def __getitem__(self, key: object, /) -> object: ... + def __iter__(self, /) -> object: ... + def names(self, /) -> object: ... + def types(self, /) -> object: ... @deprecated("will be removed in SciPy v2.0.0") def loadarff(f: object) -> object: ... diff --git a/scipy-stubs/io/matlab/__init__.pyi b/scipy-stubs/io/matlab/__init__.pyi index 4f8ca984..ad28c9fb 100644 --- a/scipy-stubs/io/matlab/__init__.pyi +++ b/scipy-stubs/io/matlab/__init__.pyi @@ -1,20 +1,17 @@ -from . import ( - byteordercodes as byteordercodes, - mio as mio, - mio4 as mio4, - mio5 as mio5, - mio5_params as mio5_params, - mio5_utils as mio5_utils, - mio_utils as mio_utils, - miobase as miobase, - streams as streams, -) -from ._mio import loadmat as loadmat, savemat as savemat, whosmat as whosmat -from ._mio5 import MatlabFunction as MatlabFunction -from ._mio5_params import MatlabObject as MatlabObject, MatlabOpaque as MatlabOpaque, mat_struct as mat_struct -from ._miobase import ( - MatReadError as MatReadError, - MatReadWarning as MatReadWarning, - MatWriteError as MatWriteError, - matfile_version as matfile_version, -) +from ._mio import loadmat, savemat, whosmat +from ._mio5_params import MatlabFunction, MatlabObject, MatlabOpaque, mat_struct +from ._miobase import MatReadError, MatReadWarning, MatWriteError, matfile_version + +__all__ = [ + "MatReadError", + "MatReadWarning", + "MatWriteError", + "MatlabFunction", + "MatlabObject", + "MatlabOpaque", + "loadmat", + "mat_struct", + "matfile_version", + "savemat", + "whosmat", +] diff --git a/scipy-stubs/io/matlab/_byteordercodes.pyi b/scipy-stubs/io/matlab/_byteordercodes.pyi index 289474a3..38c34439 100644 --- a/scipy-stubs/io/matlab/_byteordercodes.pyi +++ b/scipy-stubs/io/matlab/_byteordercodes.pyi @@ -1,8 +1,10 @@ -from scipy._typing import Untyped +__all__ = ["aliases", "native_code", "swapped_code", "sys_is_le", "to_numpy_code"] -sys_is_le: Untyped -native_code: Untyped -swapped_code: Untyped -aliases: Untyped +from typing import Final, Literal -def to_numpy_code(code) -> Untyped: ... +sys_is_le: Final[bool] = ... +native_code: Final[Literal["<", ">"]] = ... +swapped_code: Final[Literal["<", ">"]] = ... +aliases: dict[str, tuple[str, ...]] + +def to_numpy_code(code: str) -> Literal["<", ">", "="]: ... diff --git a/scipy-stubs/io/matlab/_mio.pyi b/scipy-stubs/io/matlab/_mio.pyi index b4016220..65516a0f 100644 --- a/scipy-stubs/io/matlab/_mio.pyi +++ b/scipy-stubs/io/matlab/_mio.pyi @@ -1,17 +1,70 @@ -from scipy._typing import Untyped -from ._mio4 import MatFile4Reader as MatFile4Reader, MatFile4Writer as MatFile4Writer -from ._mio5 import MatFile5Reader as MatFile5Reader, MatFile5Writer as MatFile5Writer -from ._miobase import docfiller as docfiller +from typing import Literal, TypeAlias, TypedDict, type_check_only +from typing_extensions import Unpack -def mat_reader_factory(file_name, appendmat: bool = True, **kwargs) -> Untyped: ... -def loadmat(file_name, mdict: Untyped | None = None, appendmat: bool = True, **kwargs) -> Untyped: ... +import numpy as np +import numpy.typing as npt +from scipy._typing import ByteOrder, FileName +from ._miobase import MatFileReader + +__all__ = ["loadmat", "savemat", "whosmat"] + +_MDict: TypeAlias = dict[str, npt.NDArray[np.generic]] +_DataClass: TypeAlias = Literal[ + "int8", + "int16", + "int32", + "int64", + "uint8", + "uint16", + "uint32", + "uint64", + "single", + "double", + "cell", + "struct", + "object", + "char", + "sparse", + "function", + "opaque", + "logical", + "unknown", +] + +@type_check_only +class _ReaderKwargs(TypedDict, total=False): + byte_order: ByteOrder | None + mat_dtype: bool + squeeze_me: bool + chars_as_strings: bool + matlab_compatible: bool + struct_as_record: bool + verify_compressed_data_integrity: bool + simplify_cells: bool + variable_names: list[str] | tuple[str] | None + +def mat_reader_factory( + file_name: FileName, + appendmat: bool = True, + **kwargs: Unpack[_ReaderKwargs], +) -> tuple[MatFileReader, bool]: ... +def loadmat( + file_name: FileName, + mdict: _MDict | None = None, + appendmat: bool = True, + **kwargs: Unpack[_ReaderKwargs], +) -> _MDict: ... def savemat( - file_name, - mdict, + file_name: FileName, + mdict: _MDict, appendmat: bool = True, - format: str = "5", + format: Literal["5", "4"] = "5", long_field_names: bool = False, do_compression: bool = False, - oned_as: str = "row", -): ... -def whosmat(file_name, appendmat: bool = True, **kwargs) -> Untyped: ... + oned_as: Literal["row", "column"] = "row", +) -> None: ... +def whosmat( + file_name: FileName, + appendmat: bool = True, + **kwargs: Unpack[_ReaderKwargs], +) -> list[tuple[str, tuple[int, ...], _DataClass]]: ... diff --git a/scipy-stubs/io/matlab/_mio4.pyi b/scipy-stubs/io/matlab/_mio4.pyi index 66819375..95740ef2 100644 --- a/scipy-stubs/io/matlab/_mio4.pyi +++ b/scipy-stubs/io/matlab/_mio4.pyi @@ -1,4 +1,10 @@ -from scipy._typing import Untyped +from collections.abc import Mapping, Sequence +from typing import IO, Any, Final, Generic, Literal, Protocol, TypeAlias, type_check_only +from typing_extensions import LiteralString, TypeVar + +import numpy as np +import numpy.typing as npt +from scipy.sparse import coo_matrix, sparray, spmatrix from ._miobase import MatFileReader __all__ = [ @@ -24,72 +30,101 @@ __all__ = [ "order_codes", ] -SYS_LITTLE_ENDIAN: Untyped -miDOUBLE: int -miSINGLE: int -miINT32: int -miINT16: int -miUINT16: int -miUINT8: int -mdtypes_template: Untyped -np_to_mtypes: Untyped -mxFULL_CLASS: int -mxCHAR_CLASS: int -mxSPARSE_CLASS: int -order_codes: Untyped -mclass_info: Untyped - -class VarHeader4: - is_logical: bool - is_global: bool - name: Untyped - dtype: Untyped - mclass: Untyped - dims: Untyped - is_complex: Untyped - def __init__(self, name, dtype, mclass, dims, is_complex) -> None: ... +_OnedAs: TypeAlias = Literal["row", "col"] +_MDType: TypeAlias = Literal[0, 1, 2, 3, 4, 5] +_MClass: TypeAlias = Literal[0, 1, 2] + +SYS_LITTLE_ENDIAN: Final[bool] = ... + +miDOUBLE: Final = 0 +miSINGLE: Final = 1 +miINT32: Final = 2 +miINT16: Final = 3 +miUINT16: Final = 4 +miUINT8: Final = 5 + +mxFULL_CLASS: Final = 0 +mxCHAR_CLASS: Final = 1 +mxSPARSE_CLASS: Final = 2 + +mdtypes_template: Final[dict[int | str, str | list[tuple[str, str]]]] +np_to_mtypes: Final[dict[str, int]] +order_codes: Final[dict[int, str]] +mclass_info: Final[dict[int, str]] + +_DT = TypeVar("_DT", bound=np.dtype[np.generic]) +_DT_co = TypeVar("_DT_co", covariant=True, bound=np.dtype[np.generic], default=np.dtype[np.generic]) + +@type_check_only +class _SupportsVarHeader(Protocol[_DT_co]): + @property + def name(self, /) -> str: ... + @property + def dtype(self, /) -> _DT_co: ... + @property + def mclass(self, /) -> _MClass: ... + @property + def dims(self, /) -> int: ... + @property + def is_global(self, /) -> bool: ... + +# NOTE: `VarHeader4` is assignable to `_SupportsVarHeader` +class VarHeader4(Generic[_DT_co]): + name: LiteralString + dtype: _DT_co + dims: Final[int] + mclass: Final[_MClass] + is_complex: Final[bool] + is_logical: Final[bool] + is_global: Final[bool] + + def __init__(self, /, name: str, dtype: _DT_co, mclass: _MClass, dims: int, is_complex: bool) -> None: ... class VarReader4: - file_reader: Untyped - mat_stream: Untyped - dtypes: Untyped - chars_as_strings: Untyped - squeeze_me: Untyped - def __init__(self, file_reader) -> None: ... - def read_header(self) -> Untyped: ... - def array_from_header(self, hdr, process: bool = True) -> Untyped: ... - def read_sub_array(self, hdr, copy: bool = True) -> Untyped: ... - def read_full_array(self, hdr) -> Untyped: ... - def read_char_array(self, hdr) -> Untyped: ... - def read_sparse_array(self, hdr) -> Untyped: ... - def shape_from_header(self, hdr) -> Untyped: ... + file_reader: Final[MatFileReader] + mat_stream: Final[IO[bytes]] + dtypes: Final[Mapping[str, np.dtype[np.generic]]] + chars_as_strings: Final[bool] + squeeze_me: Final[bool] + + def __init__(self, /, file_reader: MatFileReader) -> None: ... + def read_header(self, /) -> tuple[VarHeader4, int]: ... + def array_from_header( + self, + /, + hdr: _SupportsVarHeader[_DT], + process: bool = True, + ) -> np.ndarray[tuple[int, ...], _DT] | coo_matrix: ... + def read_sub_array(self, /, hdr: _SupportsVarHeader[_DT], copy: bool = True) -> np.ndarray[tuple[int, ...], _DT]: ... + def read_full_array(self, /, hdr: _SupportsVarHeader[_DT]) -> np.ndarray[tuple[int, ...], _DT]: ... + def read_char_array(self, /, hdr: _SupportsVarHeader[_DT]) -> np.ndarray[tuple[int, ...], _DT]: ... + def read_sparse_array(self, /, hdr: _SupportsVarHeader) -> coo_matrix: ... + def shape_from_header(self, /, hdr: _SupportsVarHeader) -> tuple[int, ...]: ... class MatFile4Reader(MatFileReader): - def __init__(self, mat_stream, *args, **kwargs) -> None: ... - def guess_byte_order(self) -> Untyped: ... - dtypes: Untyped - def initialize_read(self): ... - def read_var_header(self) -> Untyped: ... - def read_var_array(self, header, process: bool = True) -> Untyped: ... - def get_variables(self, variable_names: Untyped | None = None) -> Untyped: ... - def list_variables(self) -> Untyped: ... + def __init__(self, /, mat_stream: IO[bytes], *args: bool | str, **kwargs: bool | str) -> None: ... + def initialize_read(self, /) -> None: ... + def read_var_header(self, /) -> tuple[VarHeader4, int]: ... + def read_var_array(self, /, header: _SupportsVarHeader[_DT], process: bool = True) -> np.ndarray[tuple[int, ...], _DT]: ... + def get_variables(self, /, variable_names: str | Sequence[str] | None = None) -> dict[str, npt.NDArray[np.generic]]: ... + def list_variables(self, /) -> list[tuple[str, tuple[int, ...], str]]: ... -def arr_to_2d(arr, oned_as: str = "row") -> Untyped: ... +def arr_to_2d(arr: npt.NDArray[np.generic], oned_as: _OnedAs = "row") -> np.ndarray[tuple[int, int], np.dtype[np.generic]]: ... class VarWriter4: - file_stream: Untyped - oned_as: Untyped - def __init__(self, file_writer) -> None: ... - def write_bytes(self, arr): ... - def write_string(self, s): ... - def write_header(self, name, shape, P=..., T=..., imagf: int = 0): ... - def write(self, arr, name): ... - def write_numeric(self, arr, name): ... - def write_char(self, arr, name): ... - def write_sparse(self, arr, name): ... + file_stream: IO[bytes] + oned_as: _OnedAs + def __init__(self, /, file_writer: MatFile4Writer) -> None: ... + def write_bytes(self, /, arr: npt.NDArray[np.generic]) -> 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_numeric(self, /, arr: npt.NDArray[np.number[Any]], name: str) -> None: ... + def write_char(self, /, arr: npt.NDArray[np.character], name: str) -> None: ... + def write_sparse(self, /, arr: spmatrix | sparray, name: str) -> None: ... class MatFile4Writer: - file_stream: Untyped - oned_as: Untyped - def __init__(self, file_stream, oned_as: Untyped | None = None): ... - def put_variables(self, mdict, write_header: Untyped | None = None): ... + file_stream: IO[bytes] + oned_as: _OnedAs + def __init__(self, /, file_stream: IO[bytes], oned_as: _OnedAs | None = None) -> None: ... + def put_variables(self, /, mdict: Mapping[str, npt.NDArray[np.generic]], write_header: bool | None = None) -> None: ... diff --git a/scipy-stubs/io/matlab/_mio5.pyi b/scipy-stubs/io/matlab/_mio5.pyi index b4a43487..430c1a31 100644 --- a/scipy-stubs/io/matlab/_mio5.pyi +++ b/scipy-stubs/io/matlab/_mio5.pyi @@ -1,110 +1,108 @@ -from scipy._typing import Untyped -from ._byteordercodes import native_code as native_code, swapped_code as swapped_code -from ._mio5_params import ( - MDTYPES as MDTYPES, - NP_TO_MTYPES as NP_TO_MTYPES, - NP_TO_MXTYPES as NP_TO_MXTYPES, - MatlabFunction as MatlabFunction, - MatlabObject as MatlabObject, - mat_struct as mat_struct, - mclass_info as mclass_info, - miCOMPRESSED as miCOMPRESSED, - miINT8 as miINT8, - miMATRIX as miMATRIX, - miUINT32 as miUINT32, - miUTF8 as miUTF8, - mxCELL_CLASS as mxCELL_CLASS, - mxCHAR_CLASS as mxCHAR_CLASS, - mxDOUBLE_CLASS as mxDOUBLE_CLASS, - mxOBJECT_CLASS as mxOBJECT_CLASS, - mxSPARSE_CLASS as mxSPARSE_CLASS, - mxSTRUCT_CLASS as mxSTRUCT_CLASS, -) -from ._miobase import ( - MatFileReader as MatFileReader, - MatReadError as MatReadError, - MatReadWarning as MatReadWarning, - MatWriteError as MatWriteError, - arr_dtype_number as arr_dtype_number, - arr_to_chars as arr_to_chars, - docfiller as docfiller, - matdims as matdims, - read_dtype as read_dtype, -) +import io +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 +from scipy._typing import AnyShape, ByteOrder +from scipy.sparse import sparray, spmatrix +from ._miobase import MatFileReader + +_GenericArray: TypeAlias = np.ndarray[tuple[int, ...], np.dtype[np.generic]] +_OnedAs: TypeAlias = Literal["row", "column"] + +@type_check_only +class _MatFile5Header(TypedDict): + __header__: str + __version__: str + +NDT_FILE_HDR: Final[np.dtype[np.generic]] +NDT_TAG_FULL: Final[np.dtype[np.generic]] +NDT_TAG_SMALL: Final[np.dtype[np.generic]] +NDT_ARRAY_FLAGS: Final[np.dtype[np.generic]] + +@final +class EmptyStructMarker: ... class MatFile5Reader(MatFileReader): - uint16_codec: Untyped + uint16_codec: Final[str] + def __init__( self, - mat_stream, - byte_order: Untyped | None = None, + /, + mat_stream: IO[bytes], + byte_order: ByteOrder | None = None, mat_dtype: bool = False, squeeze_me: bool = False, chars_as_strings: bool = True, matlab_compatible: bool = False, struct_as_record: bool = True, verify_compressed_data_integrity: bool = True, - uint16_codec: Untyped | None = None, + uint16_codec: str | None = None, simplify_cells: bool = False, - ): ... - def guess_byte_order(self) -> Untyped: ... - def read_file_header(self) -> Untyped: ... - def initialize_read(self): ... - def read_var_header(self) -> Untyped: ... - def read_var_array(self, header, process: bool = True) -> Untyped: ... - def get_variables(self, variable_names: Untyped | None = None) -> Untyped: ... - def list_variables(self) -> Untyped: ... - -def varmats_from_mat(file_obj) -> Untyped: ... - -class EmptyStructMarker: ... - -def to_writeable(source) -> Untyped: ... - -NDT_FILE_HDR: Untyped -NDT_TAG_FULL: Untyped -NDT_TAG_SMALL: Untyped -NDT_ARRAY_FLAGS: Untyped + ) -> None: ... + def read_file_header(self, /) -> _MatFile5Header: ... + def initialize_read(self, /) -> None: ... + def read_var_header(self, /) -> tuple[object, int]: ... + def read_var_array(self, /, header: Mapping[str, object], process: bool = True) -> _GenericArray: ... + def get_variables( + self, + /, + variable_names: Iterable[str] | None = None, + ) -> dict[str, str | list[str] | _GenericArray]: ... + def list_variables(self, /) -> list[tuple[str, tuple[int, ...], str]]: ... class VarWriter5: - mat_tag: Untyped - file_stream: Untyped - unicode_strings: Untyped - long_field_names: Untyped - oned_as: Untyped - def __init__(self, file_writer) -> None: ... - def write_bytes(self, arr): ... - def write_string(self, s): ... - def write_element(self, arr, mdtype: Untyped | None = None): ... - def write_smalldata_element(self, arr, mdtype, byte_count): ... - def write_regular_element(self, arr, mdtype, byte_count): ... - def write_header(self, shape, mclass, is_complex: bool = False, is_logical: bool = False, nzmax: int = 0): ... - def update_matrix_tag(self, start_pos): ... - def write_top(self, arr, name, is_global): ... - def write(self, arr): ... - def write_numeric(self, arr): ... - def write_char(self, arr, codec: str = "ascii"): ... - def write_sparse(self, arr): ... - def write_cells(self, arr): ... - def write_empty_struct(self): ... - def write_struct(self, arr): ... - def write_object(self, arr): ... + mat_tag: _GenericArray + file_stream: IO[bytes] + unicode_strings: bool + long_field_names: bool + oned_as: _OnedAs + def __init__(self, /, file_writer: MatFile5Writer) -> None: ... + def write_bytes(self, /, arr: _GenericArray) -> None: ... + def write_string(self, /, s: str) -> None: ... + def write_element(self, /, arr: _GenericArray, mdtype: int | None = None) -> None: ... + def write_smalldata_element(self, /, arr: _GenericArray, mdtype: int, byte_count: int) -> None: ... + def write_regular_element(self, /, arr: _GenericArray, mdtype: int, byte_count: int) -> None: ... + def write_header( + self, + /, + shape: AnyShape, + mclass: int, + is_complex: bool = False, + is_logical: bool = False, + 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_numeric(self, /, arr: npt.NDArray[np.bool_ | np.number[Any]]) -> None: ... + def write_char(self, /, arr: npt.NDArray[np.str_], codec: str = "ascii") -> None: ... + def write_sparse(self, /, arr: spmatrix | sparray) -> None: ... + def write_cells(self, /, arr: _GenericArray) -> None: ... + def write_empty_struct(self, /) -> None: ... + def write_struct(self, /, arr: npt.NDArray[np.void]) -> None: ... + def write_object(self, /, arr: npt.NDArray[np.object_]) -> None: ... class MatFile5Writer: - file_stream: Untyped - do_compression: Untyped - unicode_strings: Untyped - global_vars: Untyped - long_field_names: Untyped - oned_as: Untyped + file_stream: IO[bytes] + do_compression: bool + unicode_strings: bool + global_vars: list[str] | tuple[str, ...] + long_field_names: bool + oned_as: _OnedAs def __init__( self, - file_stream, + /, + file_stream: IO[bytes], do_compression: bool = False, unicode_strings: bool = False, - global_vars: Untyped | None = None, + global_vars: list[str] | tuple[str, ...] | None = None, long_field_names: bool = False, - oned_as: str = "row", - ): ... - def write_file_header(self): ... - def put_variables(self, mdict, write_header: Untyped | None = None): ... + oned_as: _OnedAs = "row", + ) -> None: ... + def write_file_header(self, /) -> None: ... + def put_variables(self, /, mdict: Mapping[str, _GenericArray], write_header: bool | None = None) -> None: ... + +def varmats_from_mat(file_obj: IO[bytes]) -> list[tuple[str, io.BytesIO]]: ... +def to_writeable(source: object) -> _GenericArray | type[EmptyStructMarker] | None: ... diff --git a/scipy-stubs/io/matlab/_mio5_params.pyi b/scipy-stubs/io/matlab/_mio5_params.pyi index c62d7fb6..df9d7cc7 100644 --- a/scipy-stubs/io/matlab/_mio5_params.pyi +++ b/scipy-stubs/io/matlab/_mio5_params.pyi @@ -1,8 +1,9 @@ -from typing import Literal +from typing import Final, Literal, TypeAlias, final from typing_extensions import Self, override import numpy as np -from scipy._typing import Untyped, UntypedDict +import numpy.typing as npt +import optype.numpy as onpt __all__ = [ "MDTYPES", @@ -52,60 +53,68 @@ __all__ = [ "mxUINT64_CLASS", ] -miINT8: int -miUINT8: int -miINT16: int -miUINT16: int -miINT32: int -miUINT32: int -miSINGLE: int -miDOUBLE: int -miINT64: int -miUINT64: int -miMATRIX: int -miCOMPRESSED: int -miUTF8: int -miUTF16: int -miUTF32: int -mxCELL_CLASS: int -mxSTRUCT_CLASS: int -mxOBJECT_CLASS: int -mxCHAR_CLASS: int -mxSPARSE_CLASS: int -mxDOUBLE_CLASS: int -mxSINGLE_CLASS: int -mxINT8_CLASS: int -mxUINT8_CLASS: int -mxINT16_CLASS: int -mxUINT16_CLASS: int -mxINT32_CLASS: int -mxUINT32_CLASS: int -mxINT64_CLASS: int -mxUINT64_CLASS: int -mxFUNCTION_CLASS: int -mxOPAQUE_CLASS: int -mxOBJECT_CLASS_FROM_MATRIX_H: int -mdtypes_template: UntypedDict -mclass_dtypes_template: dict[int, str] -mclass_info: dict[int, str] -NP_TO_MTYPES: dict[str, int] -NP_TO_MXTYPES: dict[str, int] -codecs_template: dict[int, dict[str, str]] -MDTYPES: UntypedDict +_MType: TypeAlias = Literal[1, 2, 3, 4, 5, 6, 7, 9, 12, 13, 14, 15, 16, 17, 18] +_MXType: TypeAlias = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] +miINT8: Final = 1 +miUINT8: Final = 2 +miINT16: Final = 3 +miUINT16: Final = 4 +miINT32: Final = 5 +miUINT32: Final = 6 +miSINGLE: Final = 7 +miDOUBLE: Final = 9 +miINT64: Final = 12 +miUINT64: Final = 13 +miMATRIX: Final = 14 +miCOMPRESSED: Final = 15 +miUTF8: Final = 16 +miUTF16: Final = 17 +miUTF32: Final = 18 + +mxCELL_CLASS: Final = 1 +mxSTRUCT_CLASS: Final = 2 +mxOBJECT_CLASS: Final = 3 +mxCHAR_CLASS: Final = 4 +mxSPARSE_CLASS: Final = 5 +mxDOUBLE_CLASS: Final = 6 +mxSINGLE_CLASS: Final = 7 +mxINT8_CLASS: Final = 8 +mxUINT8_CLASS: Final = 9 +mxINT16_CLASS: Final = 10 +mxUINT16_CLASS: Final = 11 +mxINT32_CLASS: Final = 12 +mxUINT32_CLASS: Final = 13 +mxINT64_CLASS: Final = 14 +mxUINT64_CLASS: Final = 15 +mxFUNCTION_CLASS: Final = 16 +mxOPAQUE_CLASS: Final = 17 +mxOBJECT_CLASS_FROM_MATRIX_H: Final = 18 + +codecs_template: dict[Literal[16, 17, 18], dict[Literal["codec", "width"], Literal["utf_8", "utf_16", "utf_32", 1, 2, 4]]] +mdtypes_template: Final[dict[_MType | str, str | list[tuple[str, str]]]] +mclass_info: Final[dict[_MXType, str]] +mclass_dtypes_template: Final[dict[_MXType, str]] + +NP_TO_MTYPES: Final[dict[str, _MType]] +NP_TO_MXTYPES: Final[dict[str, _MXType]] +MDTYPES: Final[dict[Literal["<", ">"], dict[str, dict[_MType, str]]]] +OPAQUE_DTYPE: Final[np.dtypes.VoidDType[Literal[32]]] + +@final class mat_struct: ... -class MatlabObject(np.ndarray[tuple[int, ...], np.dtype[np.void]]): - classname: str | None +class MatlabObject(np.ndarray[tuple[int, ...], np.dtypes.VoidDType[int]]): + classname: Final[str | None] - def __new__(cls, input_array: np.ndarray[tuple[int, ...], np.dtype[np.void]], classname: Untyped | None = None) -> Self: ... + def __new__(cls, input_array: onpt.AnyVoidArray, classname: str | None = None) -> Self: ... @override - def __array_finalize__(self, obj: Self) -> None: ... # type: ignore[override] + def __array_finalize__(self, /, obj: None | npt.NDArray[np.void]) -> None: ... class MatlabFunction(np.ndarray[tuple[int, ...], np.dtype[np.void]]): - def __new__(cls, input_array: np.ndarray[tuple[int, ...], np.dtype[np.void]]) -> Self: ... + @override + def __new__(cls, input_array: onpt.AnyVoidArray) -> Self: ... class MatlabOpaque(np.ndarray[tuple[int, ...], np.dtype[np.void]]): - def __new__(cls, input_array: np.ndarray[tuple[int, ...], np.dtype[np.void]]) -> Self: ... - -OPAQUE_DTYPE: np.dtypes.VoidDType[Literal[32]] + @override + def __new__(cls, input_array: onpt.AnyVoidArray) -> Self: ... diff --git a/scipy-stubs/io/matlab/_miobase.pyi b/scipy-stubs/io/matlab/_miobase.pyi index 8394f7a0..32afe46c 100644 --- a/scipy-stubs/io/matlab/_miobase.pyi +++ b/scipy-stubs/io/matlab/_miobase.pyi @@ -1,40 +1,54 @@ -from scipy._lib import doccer as doccer -from scipy._typing import Untyped +import abc +from collections.abc import Mapping +from typing import IO, Final, Literal, TypeVar + +import numpy as np +import numpy.typing as npt +import optype as op +import optype.numpy as onpt +from scipy._typing import ByteOrder, FileName + +__all__ = ["MatReadError", "MatReadWarning", "MatWriteError"] + +_T = TypeVar("_T", bound=op.HasDoc) + +doc_dict: Final[dict[str, str]] = ... class MatReadError(Exception): ... class MatWriteError(Exception): ... class MatReadWarning(UserWarning): ... -doc_dict: Untyped -docfiller: Untyped - -def convert_dtypes(dtype_template, order_code) -> Untyped: ... -def read_dtype(mat_stream, a_dtype) -> Untyped: ... -def matfile_version(file_name, *, appendmat: bool = True) -> Untyped: ... +def convert_dtypes(dtype_template: Mapping[str, str], order_code: ByteOrder) -> dict[str, np.dtype[np.generic]]: ... +def read_dtype(mat_stream: IO[bytes], a_dtype: npt.DTypeLike) -> npt.NDArray[np.generic]: ... +def matfile_version(file_name: FileName, *, appendmat: bool = True) -> tuple[Literal[0, 1, 2], int]: ... get_matfile_version = matfile_version -def matdims(arr, oned_as: str = "column") -> Untyped: ... +def matdims(arr: npt.NDArray[np.generic], oned_as: Literal["column", "row"] = "column") -> onpt.AtLeast1D: ... class MatVarReader: - def __init__(self, file_reader) -> None: ... - def read_header(self): ... - def array_from_header(self, header): ... + def __init__(self, /, file_reader: object) -> None: ... + @abc.abstractmethod + def read_header(self, /) -> dict[str, object]: ... + @abc.abstractmethod + def array_from_header(self, /, header: Mapping[str, object]) -> npt.NDArray[np.generic]: ... class MatFileReader: - mat_stream: Untyped - dtypes: Untyped - byte_order: Untyped - struct_as_record: Untyped - squeeze_me: Untyped - chars_as_strings: Untyped - mat_dtype: Untyped - verify_compressed_data_integrity: Untyped - simplify_cells: Untyped + mat_stream: Final[IO[bytes]] + dtypes: Final[Mapping[str, np.dtype[np.generic]]] + byte_order: Final[ByteOrder] + struct_as_record: Final[bool] + verify_compressed_data_integrity: Final[bool] + simplify_cells: Final[bool] + mat_dtype: bool + squeeze_me: bool + chars_as_strings: bool + def __init__( self, - mat_stream, - byte_order: Untyped | None = None, + /, + mat_stream: IO[bytes], + byte_order: ByteOrder | None = None, mat_dtype: bool = False, squeeze_me: bool = False, chars_as_strings: bool = True, @@ -42,10 +56,11 @@ class MatFileReader: struct_as_record: bool = True, verify_compressed_data_integrity: bool = True, simplify_cells: bool = False, - ): ... - def set_matlab_compatible(self): ... - def guess_byte_order(self) -> Untyped: ... - def end_of_stream(self) -> Untyped: ... + ) -> None: ... + def set_matlab_compatible(self, /) -> None: ... + def guess_byte_order(self, /) -> ByteOrder: ... + def end_of_stream(self, /) -> bool: ... -def arr_dtype_number(arr, num) -> Untyped: ... -def arr_to_chars(arr) -> Untyped: ... +def arr_dtype_number(arr: onpt.HasDType[np.dtype[np.character]], num: int | str) -> np.dtype[np.character]: ... +def arr_to_chars(arr: npt.NDArray[np.str_]) -> npt.NDArray[np.str_]: ... +def docfiller(f: _T) -> _T: ... diff --git a/scipy-stubs/io/matlab/byteordercodes.pyi b/scipy-stubs/io/matlab/byteordercodes.pyi index c9c2ef67..e1ba03e9 100644 --- a/scipy-stubs/io/matlab/byteordercodes.pyi +++ b/scipy-stubs/io/matlab/byteordercodes.pyi @@ -1 +1,3 @@ +# This module is not meant for public use and will be removed in SciPy v2.0.0. + __all__: list[str] = [] diff --git a/scipy-stubs/io/matlab/mio.pyi b/scipy-stubs/io/matlab/mio.pyi index 2ca6d3e2..510c049b 100644 --- a/scipy-stubs/io/matlab/mio.pyi +++ b/scipy-stubs/io/matlab/mio.pyi @@ -1,4 +1,5 @@ # This module is not meant for public use and will be removed in SciPy v2.0.0. + from typing_extensions import deprecated __all__ = ["loadmat", "savemat", "whosmat"] diff --git a/scipy-stubs/io/matlab/mio4.pyi b/scipy-stubs/io/matlab/mio4.pyi index c9c2ef67..e1ba03e9 100644 --- a/scipy-stubs/io/matlab/mio4.pyi +++ b/scipy-stubs/io/matlab/mio4.pyi @@ -1 +1,3 @@ +# This module is not meant for public use and will be removed in SciPy v2.0.0. + __all__: list[str] = [] diff --git a/scipy-stubs/io/matlab/mio5.pyi b/scipy-stubs/io/matlab/mio5.pyi index 4059dc02..e6de98c2 100644 --- a/scipy-stubs/io/matlab/mio5.pyi +++ b/scipy-stubs/io/matlab/mio5.pyi @@ -1,25 +1,27 @@ # This module is not meant for public use and will be removed in SciPy v2.0.0. + from typing_extensions import Self, deprecated +import numpy as np + __all__ = ["MatReadError", "MatReadWarning", "MatWriteError", "MatlabFunction", "MatlabObject", "mat_struct", "varmats_from_mat"] @deprecated("will be removed in SciPy v2.0.0") -class MatReadError: ... +class MatReadError(Exception): ... @deprecated("will be removed in SciPy v2.0.0") -class MatWriteError: ... +class MatWriteError(Exception): ... @deprecated("will be removed in SciPy v2.0.0") -class MatReadWarning: ... +class MatReadWarning(UserWarning): ... @deprecated("will be removed in SciPy v2.0.0") -class MatlabFunction: - def __new__(cls, input_array: object) -> Self: ... +class MatlabObject(np.ndarray[tuple[int, ...], np.dtype[np.generic]]): + def __new__(cls, input_array: object, classname: object = ...) -> Self: ... @deprecated("will be removed in SciPy v2.0.0") -class MatlabObject: - def __new__(cls, input_array: object, classname: object = ...) -> Self: ... - def __array_finalize__(self, obj: Self) -> None: ... +class MatlabFunction(MatlabObject): + def __new__(cls, input_array: object) -> Self: ... @deprecated("will be removed in SciPy v2.0.0") class mat_struct: ... diff --git a/scipy-stubs/io/matlab/mio5_params.pyi b/scipy-stubs/io/matlab/mio5_params.pyi index e4321204..4c07e7c4 100644 --- a/scipy-stubs/io/matlab/mio5_params.pyi +++ b/scipy-stubs/io/matlab/mio5_params.pyi @@ -1,4 +1,5 @@ # This module is not meant for public use and will be removed in SciPy v2.0.0. + from typing_extensions import Self, deprecated __all__ = ["MatlabFunction", "MatlabObject", "MatlabOpaque", "mat_struct"] diff --git a/scipy-stubs/io/matlab/mio5_utils.pyi b/scipy-stubs/io/matlab/mio5_utils.pyi index c9c2ef67..e1ba03e9 100644 --- a/scipy-stubs/io/matlab/mio5_utils.pyi +++ b/scipy-stubs/io/matlab/mio5_utils.pyi @@ -1 +1,3 @@ +# This module is not meant for public use and will be removed in SciPy v2.0.0. + __all__: list[str] = [] diff --git a/scipy-stubs/io/matlab/mio_utils.pyi b/scipy-stubs/io/matlab/mio_utils.pyi index c9c2ef67..e1ba03e9 100644 --- a/scipy-stubs/io/matlab/mio_utils.pyi +++ b/scipy-stubs/io/matlab/mio_utils.pyi @@ -1 +1,3 @@ +# This module is not meant for public use and will be removed in SciPy v2.0.0. + __all__: list[str] = [] diff --git a/scipy-stubs/io/matlab/miobase.pyi b/scipy-stubs/io/matlab/miobase.pyi index da3cb5ca..fca3173e 100644 --- a/scipy-stubs/io/matlab/miobase.pyi +++ b/scipy-stubs/io/matlab/miobase.pyi @@ -1,13 +1,14 @@ # This module is not meant for public use and will be removed in SciPy v2.0.0. + from typing_extensions import deprecated __all__ = ["MatReadError", "MatReadWarning", "MatWriteError"] @deprecated("will be removed in SciPy v2.0.0") -class MatReadError: ... +class MatReadError(Exception): ... @deprecated("will be removed in SciPy v2.0.0") -class MatWriteError: ... +class MatWriteError(Exception): ... @deprecated("will be removed in SciPy v2.0.0") -class MatReadWarning: ... +class MatReadWarning(UserWarning): ... diff --git a/scipy-stubs/io/matlab/streams.pyi b/scipy-stubs/io/matlab/streams.pyi index c9c2ef67..e1ba03e9 100644 --- a/scipy-stubs/io/matlab/streams.pyi +++ b/scipy-stubs/io/matlab/streams.pyi @@ -1 +1,3 @@ +# This module is not meant for public use and will be removed in SciPy v2.0.0. + __all__: list[str] = [] diff --git a/scipy-stubs/io/mmio.pyi b/scipy-stubs/io/mmio.pyi index 724d7872..f85d3182 100644 --- a/scipy-stubs/io/mmio.pyi +++ b/scipy-stubs/io/mmio.pyi @@ -9,5 +9,10 @@ def mminfo(source: object) -> object: ... def mmread(source: object) -> object: ... @deprecated("will be removed in SciPy v2.0.0") def mmwrite( - target: object, a: object, comment: object = ..., field: object = ..., precision: object = ..., symmetry: object = ... + target: object, + a: object, + comment: object = ..., + field: object = ..., + precision: object = ..., + symmetry: object = ..., ) -> None: ... diff --git a/scipy-stubs/io/netcdf.pyi b/scipy-stubs/io/netcdf.pyi index 9459a2ac..429be3f5 100644 --- a/scipy-stubs/io/netcdf.pyi +++ b/scipy-stubs/io/netcdf.pyi @@ -6,7 +6,12 @@ __all__ = ["netcdf_file", "netcdf_variable"] @deprecated("will be removed in SciPy v2.0.0") class netcdf_file: def __init__( - self, filename: object, mode: object = ..., mmap: object = ..., version: object = ..., maskandscale: object = ... + self, + filename: object, + mode: object = ..., + mmap: object = ..., + version: object = ..., + maskandscale: object = ..., ) -> None: ... def flush(self) -> None: ... def close(self) -> None: ... diff --git a/scipy-stubs/io/wavfile.pyi b/scipy-stubs/io/wavfile.pyi index 9addfdd3..6b593040 100644 --- a/scipy-stubs/io/wavfile.pyi +++ b/scipy-stubs/io/wavfile.pyi @@ -1,6 +1,18 @@ from enum import IntEnum +from typing import TypeAlias -from scipy._typing import Untyped +import numpy as np +import optype.numpy as onpt +from scipy._typing import FileLike + +__all__ = ["WavFileWarning", "read", "write"] + +_ScalarR: TypeAlias = np.uint8 | np.int16 | np.int32 | np.float32 +_ScalarW: TypeAlias = _ScalarR | np.int_ | np.int64 | np.float64 +_Shape1D: TypeAlias = tuple[int] +_Shape2D: TypeAlias = tuple[int, int] + +KNOWN_WAVE_FORMATS: set[WAVE_FORMAT] class WavFileWarning(UserWarning): ... @@ -273,7 +285,5 @@ class WAVE_FORMAT(IntEnum): EXTENSIBLE: int DEVELOPMENT: int -KNOWN_WAVE_FORMATS: Untyped - -def read(filename, mmap: bool = False) -> Untyped: ... -def write(filename, rate, data): ... +def read(filename: FileLike[bytes], mmap: bool = False) -> onpt.Array[_Shape1D | _Shape2D, _ScalarR]: ... +def write(filename: FileLike[bytes], rate: int, data: onpt.Array[_Shape1D | _Shape2D, _ScalarW]) -> None: ... diff --git a/scipy-stubs/linalg/_matfuncs_inv_ssq.pyi b/scipy-stubs/linalg/_matfuncs_inv_ssq.pyi index c579c169..22324607 100644 --- a/scipy-stubs/linalg/_matfuncs_inv_ssq.pyi +++ b/scipy-stubs/linalg/_matfuncs_inv_ssq.pyi @@ -1,12 +1,7 @@ import numpy as np -import numpy.typing as npt -from scipy.sparse.linalg._interface import LinearOperator class LogmRankWarning(UserWarning): ... class LogmExactlySingularWarning(LogmRankWarning): ... class LogmNearlySingularWarning(LogmRankWarning): ... class LogmError(np.linalg.LinAlgError): ... class FractionalMatrixPowerError(np.linalg.LinAlgError): ... - -class _MatrixM1PowerOperator(LinearOperator): - def __init__(self, A: npt.NDArray[np.number[npt.NBitBase]], p: int) -> None: ...