Skip to content

Commit

Permalink
👽️ io: 1.15.0 support (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenham authored Dec 16, 2024
1 parent e871b24 commit 7161ada
Show file tree
Hide file tree
Showing 15 changed files with 182 additions and 81 deletions.
12 changes: 0 additions & 12 deletions .mypyignore-todo
Original file line number Diff line number Diff line change
@@ -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__
Expand Down
2 changes: 1 addition & 1 deletion scipy-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
31 changes: 23 additions & 8 deletions scipy-stubs/io/_fast_matrix_market/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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,
/,
Expand All @@ -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]: ...
4 changes: 3 additions & 1 deletion scipy-stubs/io/_harwell_boeing/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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
43 changes: 32 additions & 11 deletions scipy-stubs/io/_harwell_boeing/hb.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -48,14 +55,16 @@ class HBInfo:
@classmethod
def from_data(
cls,
m: sparray | spmatrix,
m: _spbase,
title: str = "Default title",
key: str = "0",
mxtype: HBMatrixType | None = None,
fmt: None = None,
) -> Self: ...
@classmethod
def from_file(cls, fid: IO[str]) -> Self: ...

#
def __init__(
self,
/,
Expand All @@ -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
Expand All @@ -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: ...
4 changes: 3 additions & 1 deletion scipy-stubs/io/_idl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]]] = ...
Expand All @@ -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(
Expand Down
55 changes: 41 additions & 14 deletions scipy-stubs/io/_mmio.pyi
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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,
/,
Expand All @@ -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: ...
7 changes: 3 additions & 4 deletions scipy-stubs/io/arff/_arffread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]] = ...
Expand Down Expand Up @@ -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: ...
7 changes: 5 additions & 2 deletions scipy-stubs/io/harwell_boeing.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
14 changes: 14 additions & 0 deletions scipy-stubs/io/matlab/__init__.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -13,5 +26,6 @@ __all__ = [
"mat_struct",
"matfile_version",
"savemat",
"varmats_from_mat",
"whosmat",
]
Loading

0 comments on commit 7161ada

Please sign in to comment.