Skip to content

Commit

Permalink
Merge pull request #112 from jorenham/complete/scipy.io
Browse files Browse the repository at this point in the history
complete `scipy.io`
  • Loading branch information
jorenham authored Oct 18, 2024
2 parents a821330 + 7fb38db commit 2b80474
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 186 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ _typetest_mypy = "mypy --config-file=pyproject.toml tests/typetests"
typetest = ["_typetest_bpr", "_typetest_mypy"]

[tool.poe.tasks.pyright]
cmd = "basedpyright scipy-stubs/$path"
args = [{name = "path", positional = true, multiple = false, default = ""}]
cmd = "basedpyright $path"
args = [{name = "path", positional = true, multiple = true, default = "scipy-stubs"}]

[tool.poe.tasks.mypy]
cmd = "mypy --config-file=pyproject.toml $path"
Expand Down
35 changes: 24 additions & 11 deletions scipy-stubs/io/_harwell_boeing/hb.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import io
from typing import Final, Literal, TypeAlias
from typing_extensions import LiteralString, Self
from typing import IO, Final, Literal, TypeAlias, type_check_only
from typing_extensions import LiteralString, Protocol, Self

from scipy._typing import FileName, Untyped
import optype.typing as opt
from scipy._typing import FileName
from scipy.sparse import csc_matrix, sparray, spmatrix

__all__ = ["hb_read", "hb_write"]
Expand All @@ -11,6 +11,15 @@ _ValueType: TypeAlias = Literal["real", "complex", "pattern", "integer"]
_Structure: TypeAlias = Literal["symmetric", "unsymmetric", "hermitian", "skewsymmetric", "rectangular"]
_Storage: TypeAlias = Literal["assembled", "elemental"]

@type_check_only
class _HasWidthAndRepeat(Protocol):
@property
def width(self, /) -> int: ...
@property
def repeat(self, /) -> int | None: ...

###

class MalformedHeader(Exception): ...
class LineOverflow(Warning): ...

Expand Down Expand Up @@ -46,7 +55,7 @@ class HBInfo:
fmt: None = None,
) -> Self: ...
@classmethod
def from_file(cls, fid: io.IOBase) -> Self: ...
def from_file(cls, fid: IO[str]) -> Self: ...
def __init__(
self,
/,
Expand All @@ -72,14 +81,14 @@ 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: ...
@property
def fortran_format(self, /) -> LiteralString: ...

class HBFile:
def __init__(self, /, file: io.IOBase, hb_info: HBMatrixType | None = None) -> None: ...
def __init__(self, /, file: IO[str], hb_info: HBMatrixType | None = None) -> None: ...
@property
def title(self, /) -> str: ...
@property
Expand All @@ -91,7 +100,11 @@ class HBFile:
@property
def storage(self, /) -> _Storage: ...
def read_matrix(self, /) -> csc_matrix: ...
def write_matrix(self, /, m: spmatrix | sparray) -> Untyped: ...
def write_matrix(self, /, m: spmatrix | sparray) -> None: ...

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: ...
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: ...
127 changes: 83 additions & 44 deletions scipy-stubs/io/_netcdf.pyi
Original file line number Diff line number Diff line change
@@ -1,46 +1,76 @@
from collections.abc import Sequence
from collections.abc import Mapping, Sequence
from types import TracebackType
from typing import IO, Final
from typing_extensions import Self
from typing import IO, Final, Generic, Literal, TypeAlias, overload
from typing_extensions import Self, TypeVar

import numpy as np
import numpy.typing as npt
from scipy._typing import FileLike, FileModeRWA, Untyped
import optype.numpy as onpt
from optype import CanIndex
from scipy._typing import FileLike, FileModeRWA

__all__ = ["netcdf_file", "netcdf_variable"]

_ShapeT_co = TypeVar("_ShapeT_co", covariant=True, bound=tuple[int, ...], default=tuple[int, ...])
_SCT = TypeVar("_SCT", bound=np.generic, default=np.generic)
_SCT_co = TypeVar("_SCT_co", covariant=True, bound=np.generic, default=np.generic)

_TypeCode: TypeAlias = Literal["b", "c", "h", "i", "f", "d"]
_TypeSize: TypeAlias = Literal[1, 2, 4, 8]
_TypeSpec: TypeAlias = tuple[_TypeCode, _TypeSize]
_TypeNC: TypeAlias = Literal[
b"\x00\x00\x00\x01",
b"\x00\x00\x00\x02",
b"\x00\x00\x00\x03",
b"\x00\x00\x00\x04",
b"\x00\x00\x00\x05",
b"\x00\x00\x00\x06",
b"\x00\x00\x00\n",
b"\x00\x00\x00\x0b",
b"\x00\x00\x00\x0c",
]
_TypeFill: TypeAlias = Literal[
b"\x81",
b"\x00",
b"\x80\x01",
b"\x80\x00\x00\x01",
b"\x7c\xf0\x00\x00",
b"\x47\x9e\x00\x00\x00\x00\x00\x00",
]

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] = ...
ABSENT: Final = b"\x00\x00\x00\x00\x00\x00\x00\x00"
ZERO: Final = b"\x00\x00\x00\x00"
NC_BYTE: Final[_TypeNC] = b"\x00\x00\x00\x01"
NC_CHAR: Final[_TypeNC] = b"\x00\x00\x00\x02"
NC_SHORT: Final[_TypeNC] = b"\x00\x00\x00\x03"
NC_INT: Final[_TypeNC] = b"\x00\x00\x00\x04"
NC_FLOAT: Final[_TypeNC] = b"\x00\x00\x00\x05"
NC_DOUBLE: Final[_TypeNC] = b"\x00\x00\x00\x06"
NC_DIMENSION: Final[_TypeNC] = b"\x00\x00\x00\n"
NC_VARIABLE: Final[_TypeNC] = b"\x00\x00\x00\x0b"
NC_ATTRIBUTE: Final[_TypeNC] = b"\x00\x00\x00\x0c"
FILL_BYTE: Final[_TypeFill] = b"\x81"
FILL_CHAR: Final[_TypeFill] = b"\x00"
FILL_SHORT: Final[_TypeFill] = b"\x80\x01"
FILL_INT: Final[_TypeFill] = b"\x80\x00\x00\x01"
FILL_FLOAT: Final[_TypeFill] = b"\x7c\xf0\x00\x00"
FILL_DOUBLE: Final[_TypeFill] = b"\x47\x9e\x00\x00\x00\x00\x00\x00"

TYPEMAP: Final[dict[bytes, tuple[str, int]]]
FILLMAP: Final[dict[bytes, bytes]]
REVERSE: Final[dict[tuple[str, int], bytes]]
TYPEMAP: Final[dict[_TypeNC, _TypeSpec]] = ...
FILLMAP: Final[dict[_TypeNC, _TypeFill]]
REVERSE: Final[dict[_TypeSpec, _TypeNC]]

class netcdf_file:
fp: IO[bytes]
filename: str
use_mmap: bool
mode: FileModeRWA
version_byte: int
maskandscale: Untyped
dimensions: dict[str, int]
variables: dict[str, netcdf_variable]
fp: Final[IO[bytes]]
filename: Final[str]
use_mmap: Final[bool]
mode: Final[FileModeRWA]
version_byte: Final[int]
maskandscale: Final[bool]
dimensions: Final[dict[str, int]]
variables: Final[dict[str, netcdf_variable]]
def __init__(
self,
/,
Expand All @@ -61,32 +91,41 @@ class netcdf_file:
) -> None: ...
def close(self, /) -> None: ...
def createDimension(self, /, name: str, length: int) -> None: ...
@overload
def createVariable(
self,
/,
name: str,
type: np.dtype[_SCT] | onpt.HasDType[np.dtype[_SCT]],
dimensions: Sequence[str],
) -> netcdf_variable[tuple[int, ...], _SCT]: ...
@overload
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: npt.ArrayLike
dimensions: Sequence[str]
maskandscale: bool
class netcdf_variable(Generic[_ShapeT_co, _SCT_co]):
data: onpt.Array[_ShapeT_co, _SCT_co]
dimensions: Final[Sequence[str]]
maskandscale: Final[bool]
@property
def isrec(self, /) -> Untyped: ...
def isrec(self, /) -> bool: ...
@property
def shape(self, /) -> Untyped: ...
def shape(self, /) -> _ShapeT_co: ...
def __init__(
self,
/,
data: npt.ArrayLike,
data: onpt.Array[_ShapeT_co, _SCT_co],
typecode: str,
size: int,
shape: Sequence[int],
shape: tuple[int, ...] | list[int],
dimensions: Sequence[str],
attributes: dict[str, object] | None = None,
attributes: Mapping[str, object] | None = None,
maskandscale: bool = False,
) -> None: ...
def __getitem__(self, /, index: object) -> object: ...
def __setitem__(self, /, index: object, data: npt.ArrayLike) -> None: ...
def getValue(self, /) -> object: ...
def __getitem__(self, /, index: CanIndex | slice | tuple[CanIndex | slice, ...]) -> _SCT | npt.NDArray[_SCT]: ...
def __setitem__(self: netcdf_variable[tuple[int, ...], _SCT], /, index: object, data: _SCT | npt.NDArray[_SCT]) -> None: ...
def getValue(self, /) -> _SCT_co: ...
def assignValue(self, /, value: object) -> None: ...
def typecode(self, /) -> str: ...
def itemsize(self, /) -> int: ...
Expand Down
24 changes: 12 additions & 12 deletions scipy-stubs/io/arff/_arffread.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ __all__ = ["ArffError", "MetaData", "ParseArffError", "loadarff"]

_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]
r_meta: Final[re.Pattern[str]] = ...
r_comment: Final[re.Pattern[str]] = ...
r_empty: Final[re.Pattern[str]] = ...
r_headerline: Final[re.Pattern[str]] = ...
r_datameta: Final[re.Pattern[str]] = ...
r_relation: Final[re.Pattern[str]] = ...
r_attribute: Final[re.Pattern[str]] = ...
r_nominal: Final[re.Pattern[str]] = ...
r_date: Final[re.Pattern[str]] = ...
r_comattrval: Final[re.Pattern[str]] = ...
r_wcomattrval: Final[re.Pattern[str]] = ...

class ArffError(OSError): ...
class ParseArffError(ArffError): ...
Expand Down Expand Up @@ -69,7 +69,7 @@ class DateAttribute(Attribute[np.datetime64]):

def __init__(self, /, name: str, date_format: str, datetime_unit: str) -> None: ...

class RelationalAttribute(Attribute[np.ndarray[tuple[int], np.dtypes.VoidDType[int]]]):
class RelationalAttribute(Attribute[np.ndarray[tuple[int], np.dtype[np.void]]]):
type_name: ClassVar = "relational"
dtype: type[np.object_]
range: None
Expand Down
20 changes: 10 additions & 10 deletions scipy-stubs/io/arff/arffread.pyi
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# This module is not meant for public use and will be removed in SciPy v2.0.0.

from typing import Final
from typing_extensions import deprecated

from ._arffread import MetaData as _MetaData

__all__ = ["ArffError", "MetaData", "ParseArffError", "loadarff"]

@deprecated("will be removed in SciPy v2.0.0")
_msg: Final = "will be removed in SciPy v2.0.0"

@deprecated(_msg)
class ArffError(OSError): ...

@deprecated("will be removed in SciPy v2.0.0")
@deprecated(_msg)
class ParseArffError(ArffError): ...

@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: ...
@deprecated(_msg)
class MetaData(_MetaData): ...

@deprecated("will be removed in SciPy v2.0.0")
@deprecated(_msg)
def loadarff(f: object) -> object: ...
Loading

0 comments on commit 2b80474

Please sign in to comment.