From 7161adaed4dff24174a7671e76d5847ba8d1cefd Mon Sep 17 00:00:00 2001 From: Joren Hammudoglu Date: Tue, 17 Dec 2024 00:53:32 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20`io`:=201.15.0=20suppor?= =?UTF-8?q?t=20(#341)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .mypyignore-todo | 12 ---- scipy-stubs/_typing.pyi | 2 +- .../io/_fast_matrix_market/__init__.pyi | 31 ++++++++--- scipy-stubs/io/_harwell_boeing/__init__.pyi | 4 +- scipy-stubs/io/_harwell_boeing/hb.pyi | 43 +++++++++++---- scipy-stubs/io/_idl.pyi | 4 +- scipy-stubs/io/_mmio.pyi | 55 ++++++++++++++----- scipy-stubs/io/arff/_arffread.pyi | 7 +-- scipy-stubs/io/harwell_boeing.pyi | 7 ++- scipy-stubs/io/matlab/__init__.pyi | 14 +++++ scipy-stubs/io/matlab/_mio.pyi | 14 ++++- scipy-stubs/io/matlab/_mio5.pyi | 33 ++++++----- scipy-stubs/io/matlab/_miobase.pyi | 22 +++++--- scipy-stubs/io/matlab/mio.pyi | 13 ++++- scipy-stubs/io/mmio.pyi | 2 +- 15 files changed, 182 insertions(+), 81 deletions(-) diff --git a/.mypyignore-todo b/.mypyignore-todo index 5e38a76f..4be9bbc7 100644 --- a/.mypyignore-todo +++ b/.mypyignore-todo @@ -1,15 +1,3 @@ -scipy\.io\._idl\.AttrDict\.__init__ -scipy\.io\._mmio\.MMFile\.read -scipy\.io\.(_?harwell_boeing\.(hb\.)?)?hb_read -scipy\.io\.((_fast_matrix_market|_?mmio)\.)?mmread -scipy\.io\.arff\._arffread\.basic_stats -scipy\.io\.arff\._arffread\.print_attribute -scipy\.io\.arff\._arffread\.test_weka -scipy\.io\.matlab\.__all__ -scipy\.io\.matlab\._miobase\.docfiller -scipy\.io\.matlab\.varmats_from_mat -scipy\.io\.(matlab\.(_?mio\.)?)?loadmat - scipy\.linalg\.(_basic\.)?solve scipy\.linalg\.(_?decomp_svd\.)?null_space scipy\.linalg\._matfuncs_expm\.__all__ diff --git a/scipy-stubs/_typing.pyi b/scipy-stubs/_typing.pyi index 53022b22..205c0eb8 100644 --- a/scipy-stubs/_typing.pyi +++ b/scipy-stubs/_typing.pyi @@ -74,7 +74,7 @@ UntypedArray: TypeAlias = onp.Array[Any, np.generic] # I/O _ByteSOrStr = TypeVar("_ByteSOrStr", bytes, str) FileName: TypeAlias = str | PathLike[str] -FileLike: TypeAlias = IO[_ByteSOrStr] | FileName +FileLike: TypeAlias = FileName | IO[_ByteSOrStr] FileModeRW: TypeAlias = Literal["r", "w"] FileModeRWA: TypeAlias = Literal[FileModeRW, "a"] diff --git a/scipy-stubs/io/_fast_matrix_market/__init__.pyi b/scipy-stubs/io/_fast_matrix_market/__init__.pyi index 366f82c5..589c13e9 100644 --- a/scipy-stubs/io/_fast_matrix_market/__init__.pyi +++ b/scipy-stubs/io/_fast_matrix_market/__init__.pyi @@ -1,27 +1,35 @@ import io -from typing import Final, Literal, TypeAlias, type_check_only +from typing import Any, Final, Literal, TypeAlias, overload, type_check_only from typing_extensions import TypedDict, Unpack, override +import numpy as np import optype.numpy as onp -from scipy._typing import FileName -from scipy.sparse import coo_matrix, sparray, spmatrix +from scipy._typing import FileLike, FileName +from scipy.sparse import coo_array, coo_matrix +from scipy.sparse._base import _spbase __all__ = ["mminfo", "mmread", "mmwrite"] +_Falsy: TypeAlias = Literal[False, 0] +_Truthy: TypeAlias = Literal[True, 1] + _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 +### + +PARALLELISM: Final = 0 +ALWAYS_FIND_SYMMETRY: Final = False + class _TextToBytesWrapper(io.BufferedReader): encoding: Final[str] errors: Final[str] + def __init__( self, /, @@ -39,13 +47,20 @@ class _TextToBytesWrapper(io.BufferedReader): @override def seek(self, /, offset: int, whence: int = 0) -> None: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] -def mmread(source: FileName) -> onp.ArrayND | coo_matrix: ... +@overload +def mmread(source: FileLike[bytes], *, spmatrix: _Truthy = True) -> onp.ArrayND[np.number[Any]] | coo_array: ... +@overload +def mmread(source: FileLike[bytes], *, spmatrix: _Falsy) -> onp.ArrayND[np.number[Any]] | coo_matrix: ... + +# def mmwrite( target: FileName, - a: onp.CanArray | list[object] | tuple[object, ...] | sparray | spmatrix, + a: onp.CanArray | list[object] | tuple[object, ...] | _spbase, 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/_harwell_boeing/__init__.pyi b/scipy-stubs/io/_harwell_boeing/__init__.pyi index 194077c0..b4ce46d4 100644 --- a/scipy-stubs/io/_harwell_boeing/__init__.pyi +++ b/scipy-stubs/io/_harwell_boeing/__init__.pyi @@ -1 +1,3 @@ -from .hb import hb_read as hb_read, hb_write as hb_write +__all__ = ["hb_read", "hb_write"] + +from .hb import hb_read, hb_write diff --git a/scipy-stubs/io/_harwell_boeing/hb.pyi b/scipy-stubs/io/_harwell_boeing/hb.pyi index df590e23..2051c9fc 100644 --- a/scipy-stubs/io/_harwell_boeing/hb.pyi +++ b/scipy-stubs/io/_harwell_boeing/hb.pyi @@ -1,16 +1,23 @@ -from typing import IO, Final, Literal, TypeAlias, type_check_only +from typing import IO, Any, Final, Literal, TypeAlias, overload, type_check_only from typing_extensions import LiteralString, Protocol, Self +import numpy as np import optype.typing as opt -from scipy._typing import FileName -from scipy.sparse import csc_matrix, sparray, spmatrix +from scipy._typing import FileLike +from scipy.sparse import csc_array, csc_matrix +from scipy.sparse._base import _spbase __all__ = ["hb_read", "hb_write"] +_Falsy: TypeAlias = Literal[False, 0] +_Truthy: TypeAlias = Literal[True, 1] + _ValueType: TypeAlias = Literal["real", "complex", "pattern", "integer"] _Structure: TypeAlias = Literal["symmetric", "unsymmetric", "hermitian", "skewsymmetric", "rectangular"] _Storage: TypeAlias = Literal["assembled", "elemental"] +_Real: TypeAlias = np.integer[Any] | np.float32 | np.float64 + @type_check_only class _HasWidthAndRepeat(Protocol): @property @@ -48,7 +55,7 @@ class HBInfo: @classmethod def from_data( cls, - m: sparray | spmatrix, + m: _spbase, title: str = "Default title", key: str = "0", mxtype: HBMatrixType | None = None, @@ -56,6 +63,8 @@ class HBInfo: ) -> Self: ... @classmethod def from_file(cls, fid: IO[str]) -> Self: ... + + # def __init__( self, /, @@ -81,14 +90,16 @@ class HBMatrixType: value_type: Final[_ValueType] structure: Final[_Structure] storage: Final[_Storage] + @property def fortran_format(self, /) -> LiteralString: ... @classmethod def from_fortran(cls, fmt: str) -> Self: ... + + # def __init__(self, /, value_type: _ValueType, structure: _Structure, storage: _Storage = "assembled") -> None: ... class HBFile: - def __init__(self, /, file: IO[str], hb_info: HBMatrixType | None = None) -> None: ... @property def title(self, /) -> str: ... @property @@ -99,12 +110,22 @@ class HBFile: def structure(self, /) -> _Structure: ... @property def storage(self, /) -> _Storage: ... - def read_matrix(self, /) -> csc_matrix: ... - def write_matrix(self, /, m: spmatrix | sparray) -> None: ... + + # + def __init__(self, /, file: IO[str], hb_info: HBMatrixType | None = None) -> None: ... + def read_matrix(self, /) -> csc_array[_Real]: ... + def write_matrix(self, /, m: _spbase) -> None: ... def _nbytes_full(fmt: _HasWidthAndRepeat, nlines: int) -> int: ... def _expect_int(value: opt.AnyInt, msg: str | None = None) -> int: ... -def _read_hb_data(content: IO[str], header: HBInfo) -> csc_matrix: ... -def _write_data(m: sparray | spmatrix, fid: IO[str], header: HBInfo) -> None: ... -def hb_read(path_or_open_file: IO[str] | FileName) -> csc_matrix: ... -def hb_write(path_or_open_file: IO[str] | FileName, m: spmatrix | sparray, hb_info: HBInfo | None = None) -> None: ... +def _read_hb_data(content: IO[str], header: HBInfo) -> csc_array[_Real]: ... +def _write_data(m: _spbase, fid: IO[str], header: HBInfo) -> None: ... + +# +@overload +def hb_read(path_or_open_file: FileLike[str], *, spmatrix: _Truthy = True) -> csc_array[_Real]: ... +@overload +def hb_read(path_or_open_file: FileLike[str], *, spmatrix: _Falsy) -> csc_matrix[_Real]: ... + +# +def hb_write(path_or_open_file: FileLike[str], m: _spbase, hb_info: HBInfo | None = None) -> None: ... diff --git a/scipy-stubs/io/_idl.pyi b/scipy-stubs/io/_idl.pyi index 8c64ee28..fdb1dc97 100644 --- a/scipy-stubs/io/_idl.pyi +++ b/scipy-stubs/io/_idl.pyi @@ -6,6 +6,8 @@ __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]]] = ... @@ -17,7 +19,7 @@ class Pointer: class ObjectPointer(Pointer): ... class AttrDict(dict[str, _VT], Generic[_VT]): - def __init__(self, /, init: dict[str, object] = ...) -> None: ... + def __init__(self, /, init: dict[str, object] | None = None) -> None: ... def __call__(self, /, name: str) -> object: ... def readsav( diff --git a/scipy-stubs/io/_mmio.pyi b/scipy-stubs/io/_mmio.pyi index 17bbfee1..3e4e0dd1 100644 --- a/scipy-stubs/io/_mmio.pyi +++ b/scipy-stubs/io/_mmio.pyi @@ -1,13 +1,17 @@ -from typing import Any, ClassVar, Literal, TypeAlias, TypedDict, type_check_only +from typing import Any, ClassVar, Literal, TypeAlias, TypedDict, overload, type_check_only from typing_extensions import Unpack import numpy as np import optype.numpy as onp from scipy._typing import FileLike from scipy.sparse import coo_matrix, sparray, spmatrix +from scipy.sparse._coo import coo_array __all__ = ["MMFile", "mminfo", "mmread", "mmwrite"] +_Falsy: TypeAlias = Literal[False, 0] +_Truthy: TypeAlias = Literal[True, 1] + _Format: TypeAlias = Literal["coordinate", "array"] _Field: TypeAlias = Literal["real", "complex", "pattern", "integer"] _Symmetry: TypeAlias = Literal["general", "symmetric", "skew-symmetric", "hermitian"] @@ -22,17 +26,7 @@ class _MMFileKwargs(TypedDict, total=False): field: _Field symmetry: _Symmetry -def asstr(s: object) -> str: ... -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 | onp.ToArrayND, - comment: str = "", - field: _Field | None = None, - precision: int | None = None, - symmetry: _Symmetry | None = None, -) -> None: ... +### class MMFile: FORMAT_COORDINATE: ClassVar[str] = "coordinate" @@ -54,7 +48,6 @@ class MMFile: DTYPES_BY_FIELD: ClassVar[dict[_Field, Literal["intp", "uint64", "d", "D"]]] = ... - def __init__(self, /, **kwargs: Unpack[_MMFileKwargs]) -> None: ... @property def rows(self, /) -> int: ... @property @@ -69,7 +62,17 @@ class MMFile: def symmetry(self, /) -> _Symmetry: ... @property def has_symmetry(self, /) -> bool: ... - def read(self, /, source: FileLike[bytes]) -> onp.ArrayND[np.number[Any]] | coo_matrix: ... + + # + def __init__(self, /, **kwargs: Unpack[_MMFileKwargs]) -> None: ... + + # + @overload + def read(self, /, source: FileLike[bytes], *, spmatrix: _Truthy = True) -> onp.ArrayND[np.number[Any]] | coo_array: ... + @overload + def read(self, /, source: FileLike[bytes], *, spmatrix: _Falsy) -> onp.ArrayND[np.number[Any]] | coo_matrix: ... + + # def write( self, /, @@ -80,9 +83,33 @@ class MMFile: 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: ... + +# +def asstr(s: object) -> str: ... + +# +@overload +def mmread(source: FileLike[bytes], *, spmatrix: _Truthy = True) -> onp.ArrayND[np.number[Any]] | coo_array: ... +@overload +def mmread(source: FileLike[bytes], *, spmatrix: _Falsy) -> onp.ArrayND[np.number[Any]] | coo_matrix: ... + +# +def mmwrite( + target: FileLike[bytes], + a: spmatrix | sparray | onp.ToArrayND, + comment: str = "", + field: _Field | None = None, + precision: int | None = None, + symmetry: _Symmetry | None = None, +) -> None: ... + +# +def mminfo(source: FileLike[bytes]) -> _Info: ... diff --git a/scipy-stubs/io/arff/_arffread.pyi b/scipy-stubs/io/arff/_arffread.pyi index 1708ea2e..bf9dcb66 100644 --- a/scipy-stubs/io/arff/_arffread.pyi +++ b/scipy-stubs/io/arff/_arffread.pyi @@ -7,12 +7,14 @@ from typing_extensions import Self, TypeVar import numpy as np import optype.numpy as onp -from scipy._typing import FileLike, FileName +from scipy._typing import FileLike __all__ = ["ArffError", "MetaData", "ParseArffError", "loadarff"] _T_co = TypeVar("_T_co", covariant=True, default=object) +### + r_meta: Final[re.Pattern[str]] = ... r_comment: Final[re.Pattern[str]] = ... r_empty: Final[re.Pattern[str]] = ... @@ -95,6 +97,3 @@ 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[onp.ArrayND[np.void], MetaData]: ... -def basic_stats(data: onp.ArrayND[np.number[Any]]) -> tuple[np.number[Any], np.number[Any], np.number[Any], np.number[Any]]: ... -def print_attribute(name: str, tp: Attribute, data: onp.ArrayND[np.number[Any]]) -> None: ... -def test_weka(filename: FileName) -> None: ... diff --git a/scipy-stubs/io/harwell_boeing.pyi b/scipy-stubs/io/harwell_boeing.pyi index 519ccc1a..9e237038 100644 --- a/scipy-stubs/io/harwell_boeing.pyi +++ b/scipy-stubs/io/harwell_boeing.pyi @@ -1,9 +1,12 @@ +# ruff: noqa: ANN401 # This module is not meant for public use and will be removed in SciPy v2.0.0. + +from typing import Any from typing_extensions import deprecated __all__ = ["hb_read", "hb_write"] @deprecated("will be removed in SciPy v2.0.0") -def hb_read(path_or_open_file: object) -> object: ... +def hb_read(path_or_open_file: object, *, spmatrix: bool = True) -> Any: ... @deprecated("will be removed in SciPy v2.0.0") -def hb_write(path_or_open_file: object, m: object, hb_info: object = ...) -> None: ... +def hb_write(path_or_open_file: object, m: object, hb_info: object = ...) -> Any: ... diff --git a/scipy-stubs/io/matlab/__init__.pyi b/scipy-stubs/io/matlab/__init__.pyi index ad28c9fb..ff5a7ba6 100644 --- a/scipy-stubs/io/matlab/__init__.pyi +++ b/scipy-stubs/io/matlab/__init__.pyi @@ -1,4 +1,17 @@ +# Deprecated namespaces, to be removed in v2.0.0 +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, savemat, whosmat +from ._mio5 import varmats_from_mat from ._mio5_params import MatlabFunction, MatlabObject, MatlabOpaque, mat_struct from ._miobase import MatReadError, MatReadWarning, MatWriteError, matfile_version @@ -13,5 +26,6 @@ __all__ = [ "mat_struct", "matfile_version", "savemat", + "varmats_from_mat", "whosmat", ] diff --git a/scipy-stubs/io/matlab/_mio.pyi b/scipy-stubs/io/matlab/_mio.pyi index 52dbde03..883e3d97 100644 --- a/scipy-stubs/io/matlab/_mio.pyi +++ b/scipy-stubs/io/matlab/_mio.pyi @@ -1,13 +1,15 @@ +from collections.abc import Mapping from typing import Literal, TypeAlias, TypedDict, type_check_only from typing_extensions import Unpack import optype.numpy as onp from scipy._typing import ByteOrder, FileName +from scipy.sparse import coo_array, coo_matrix from ._miobase import MatFileReader __all__ = ["loadmat", "savemat", "whosmat"] -_MDict: TypeAlias = dict[str, onp.ArrayND] +_MDict: TypeAlias = Mapping[str, onp.Array2D | coo_array | coo_matrix] _DataClass: TypeAlias = Literal[ "int8", "int16", @@ -42,17 +44,25 @@ class _ReaderKwargs(TypedDict, total=False): 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, + *, + spmatrix: bool = True, **kwargs: Unpack[_ReaderKwargs], ) -> _MDict: ... + +# def savemat( file_name: FileName, mdict: _MDict, @@ -62,6 +72,8 @@ def savemat( do_compression: bool = False, oned_as: Literal["row", "column"] = "row", ) -> None: ... + +# def whosmat( file_name: FileName, appendmat: bool = True, diff --git a/scipy-stubs/io/matlab/_mio5.pyi b/scipy-stubs/io/matlab/_mio5.pyi index ad10b5b4..79196b0e 100644 --- a/scipy-stubs/io/matlab/_mio5.pyi +++ b/scipy-stubs/io/matlab/_mio5.pyi @@ -8,7 +8,6 @@ from scipy._typing import AnyShape, ByteOrder from scipy.sparse import sparray, spmatrix from ._miobase import MatFileReader -_GenericArray: TypeAlias = onp.Array _OnedAs: TypeAlias = Literal["row", "column"] @type_check_only @@ -16,10 +15,12 @@ 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]] +### + +NDT_FILE_HDR: Final[np.dtype[np.void]] = ... +NDT_TAG_FULL: Final[np.dtype[np.void]] = ... +NDT_TAG_SMALL: Final[np.dtype[np.void]] = ... +NDT_ARRAY_FLAGS: Final[np.dtype[np.void]] = ... @final class EmptyStructMarker: ... @@ -44,26 +45,27 @@ class MatFile5Reader(MatFileReader): 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 read_var_array(self, /, header: Mapping[str, object], process: bool = True) -> onp.Array: ... def get_variables( self, /, variable_names: Iterable[str] | None = None, - ) -> dict[str, str | list[str] | _GenericArray]: ... + ) -> dict[str, str | list[str] | onp.Array]: ... def list_variables(self, /) -> list[tuple[str, tuple[int, ...], str]]: ... class VarWriter5: - mat_tag: _GenericArray + mat_tag: onp.Array 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_bytes(self, /, arr: onp.Array) -> 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_element(self, /, arr: onp.Array, mdtype: int | None = None) -> None: ... + def write_smalldata_element(self, /, arr: onp.Array, mdtype: int, byte_count: int) -> None: ... + def write_regular_element(self, /, arr: onp.Array, mdtype: int, byte_count: int) -> None: ... def write_header( self, /, @@ -79,7 +81,7 @@ class VarWriter5: 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: ... - def write_cells(self, /, arr: _GenericArray) -> None: ... + def write_cells(self, /, arr: onp.Array) -> None: ... def write_empty_struct(self, /) -> None: ... def write_struct(self, /, arr: onp.ArrayND[np.void]) -> None: ... def write_object(self, /, arr: onp.ArrayND[np.object_]) -> None: ... @@ -91,6 +93,7 @@ class MatFile5Writer: global_vars: list[str] | tuple[str, ...] long_field_names: bool oned_as: _OnedAs + def __init__( self, /, @@ -102,7 +105,7 @@ class MatFile5Writer: 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 put_variables(self, /, mdict: Mapping[str, onp.Array], 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: ... +def to_writeable(source: object) -> onp.Array | type[EmptyStructMarker] | None: ... diff --git a/scipy-stubs/io/matlab/_miobase.pyi b/scipy-stubs/io/matlab/_miobase.pyi index 46cba117..5a5b58ba 100644 --- a/scipy-stubs/io/matlab/_miobase.pyi +++ b/scipy-stubs/io/matlab/_miobase.pyi @@ -1,16 +1,24 @@ import abc -from collections.abc import Mapping -from typing import IO, Final, Literal, TypeVar +from collections.abc import Callable, Mapping +from typing import IO, Final, Literal, Protocol, TypeVar, type_check_only import numpy as np import numpy.typing as npt -import optype as op import optype.numpy as onp from scipy._typing import ByteOrder, FileName __all__ = ["MatReadError", "MatReadWarning", "MatWriteError"] -_T = TypeVar("_T", bound=op.HasDoc) +_FT = TypeVar("_FT", bound=Callable[..., object]) + +@type_check_only +class _Decorator(Protocol): + def __call__(self, f: _FT, /) -> _FT: ... + +### + +doc_dict: Final[dict[str, str]] = ... +docfiller: Final[_Decorator] = ... class MatReadError(Exception): ... class MatWriteError(Exception): ... @@ -51,14 +59,12 @@ class MatFileReader: def guess_byte_order(self, /) -> ByteOrder: ... def end_of_stream(self, /) -> bool: ... -doc_dict: Final[dict[str, str]] = ... -get_matfile_version = matfile_version - def _get_matfile_version(fileobj: IO[bytes]) -> tuple[Literal[1, 2], int]: ... -def docfiller(f: _T) -> _T: ... 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) -> onp.ArrayND: ... def matfile_version(file_name: FileName, *, appendmat: bool = True) -> tuple[Literal[0, 1, 2], int]: ... def matdims(arr: onp.ArrayND, oned_as: Literal["column", "row"] = "column") -> onp.AtLeast1D: ... def arr_dtype_number(arr: onp.HasDType[np.dtype[np.character]], num: int | str) -> np.dtype[np.character]: ... def arr_to_chars(arr: onp.ArrayND[np.str_]) -> onp.ArrayND[np.str_]: ... + +get_matfile_version = matfile_version diff --git a/scipy-stubs/io/matlab/mio.pyi b/scipy-stubs/io/matlab/mio.pyi index 510c049b..52cb4df8 100644 --- a/scipy-stubs/io/matlab/mio.pyi +++ b/scipy-stubs/io/matlab/mio.pyi @@ -1,11 +1,20 @@ +# ruff: noqa: ANN401 # This module is not meant for public use and will be removed in SciPy v2.0.0. +from typing import Any from typing_extensions import deprecated __all__ = ["loadmat", "savemat", "whosmat"] @deprecated("will be removed in SciPy v2.0.0") -def loadmat(file_name: object, mdict: object = ..., appendmat: object = ..., **kwargs: object) -> object: ... +def loadmat( + file_name: object, + mdict: object = ..., + appendmat: object = ..., + *, + spmatrix: bool = True, + **kwargs: object, +) -> Any: ... @deprecated("will be removed in SciPy v2.0.0") def savemat( file_name: object, @@ -17,4 +26,4 @@ def savemat( oned_as: object = ..., ) -> None: ... @deprecated("will be removed in SciPy v2.0.0") -def whosmat(file_name: object, appendmat: object = ..., **kwargs: object) -> object: ... +def whosmat(file_name: object, appendmat: object = ..., **kwargs: object) -> Any: ... diff --git a/scipy-stubs/io/mmio.pyi b/scipy-stubs/io/mmio.pyi index f85d3182..63077937 100644 --- a/scipy-stubs/io/mmio.pyi +++ b/scipy-stubs/io/mmio.pyi @@ -6,7 +6,7 @@ __all__ = ["mminfo", "mmread", "mmwrite"] @deprecated("will be removed in SciPy v2.0.0") def mminfo(source: object) -> object: ... @deprecated("will be removed in SciPy v2.0.0") -def mmread(source: object) -> object: ... +def mmread(source: object, *, spmatrix: bool = True) -> object: ... @deprecated("will be removed in SciPy v2.0.0") def mmwrite( target: object,