Skip to content

Commit 2e94f58

Browse files
authored
Merge pull request #83 from jorenham/stubtest/scipy.sparse
fix `scipy.sparse` stubtests
2 parents eb25cb8 + 37fa8d9 commit 2e94f58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+835
-423
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,6 @@ jobs:
7070
needs: lint-and-typecheck
7171
timeout-minutes: 5
7272
runs-on: ubuntu-latest
73-
strategy:
74-
fail-fast: false
75-
matrix:
76-
module: [
77-
"scipy._lib",
78-
"scipy.cluster",
79-
"scipy.constants",
80-
"scipy.datasets",
81-
"scipy.fft",
82-
"scipy.fftpack",
83-
"scipy.integrate",
84-
"scipy.interpolate",
85-
"scipy.io",
86-
"scipy.linalg",
87-
"scipy.misc",
88-
"scipy.ndimage",
89-
"scipy.odr",
90-
"scipy.optimize",
91-
"scipy.signal",
92-
# "scipy.sparse",
93-
"scipy.spatial",
94-
"scipy.special",
95-
"scipy.stats",
96-
]
9773
steps:
9874
- uses: actions/checkout@v4
9975

@@ -107,25 +83,5 @@ jobs:
10783
- name: install
10884
run: poetry install
10985

110-
- name: Run stubtest for ${{ matrix.module }}
111-
run: poe stubtest ${{ matrix.module }} -- --ignore-unused-allowlist
112-
113-
stubtest-all:
114-
timeout-minutes: 5
115-
runs-on: ubuntu-latest
116-
steps:
117-
- uses: actions/checkout@v4
118-
119-
- run: pipx install poetry poethepoet
120-
121-
- uses: actions/setup-python@v5
122-
with:
123-
python-version: "3.13"
124-
cache: poetry
125-
126-
- name: install
127-
run: poetry install
128-
129-
- name: Run stubtest (ignored)
130-
run: poe stubtest -- --concise
131-
continue-on-error: true
86+
- name: Run stubtest
87+
run: poe stubtest

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@
3838
/>
3939
</a>
4040
<!-- TODO -->
41-
<!-- <a href="https://github.com/pre-commit/pre-commit">
41+
<a href="https://github.com/pre-commit/pre-commit">
4242
<img
4343
alt="scipy-stubs - pre-commit"
4444
src="https://img.shields.io/badge/pre--commit-enabled-teal?logo=pre-commit"
4545
/>
46-
</a> -->
46+
</a>
4747
<a href="https://github.com/KotlinIsland/basedmypy">
4848
<img
4949
alt="scipy-stubs - basedmypy"
@@ -91,7 +91,7 @@ pip install scipy-stubs
9191
| `odr` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_crescent_moon: |
9292
| `optimize` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | :first_quarter_moon: |
9393
| `signal` | :heavy_check_mark: | :heavy_check_mark: | :x: | :x: | :waxing_crescent_moon: |
94-
| `sparse` | :heavy_check_mark: | :x: | :x: | :x: | :waxing_crescent_moon: |
94+
| `sparse` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | :waxing_crescent_moon: |
9595
| `spatial` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_gibbous_moon: |
9696
| `special` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :first_quarter_moon: |
9797
| `stats` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | :waxing_gibbous_moon: |

scipy-stubs/sparse/__init__.pyi

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
from . import (
2-
base as base,
3-
bsr as bsr,
4-
compressed as compressed,
5-
construct as construct,
6-
coo as coo,
7-
csc as csc,
8-
csgraph as csgraph,
9-
csr as csr,
10-
data as data,
11-
dia as dia,
12-
dok as dok,
13-
extract as extract,
14-
lil as lil,
15-
sparsetools as sparsetools,
16-
sputils as sputils,
17-
)
1+
from . import base, bsr, compressed, construct, coo, csc, csgraph, csr, data, dia, dok, extract, lil, linalg, sparsetools, sputils
182
from ._base import *
193
from ._bsr import *
204
from ._construct import *
@@ -25,5 +9,72 @@ from ._dia import *
259
from ._dok import *
2610
from ._extract import *
2711
from ._lil import *
28-
from ._matrix import spmatrix as spmatrix
12+
from ._matrix import spmatrix
2913
from ._matrix_io import *
14+
15+
__all__ = [
16+
"SparseEfficiencyWarning",
17+
"SparseWarning",
18+
"base",
19+
"block_array",
20+
"block_diag",
21+
"bmat",
22+
"bsr",
23+
"bsr_array",
24+
"bsr_matrix",
25+
"compressed",
26+
"construct",
27+
"coo",
28+
"coo_array",
29+
"coo_matrix",
30+
"csc",
31+
"csc_array",
32+
"csc_matrix",
33+
"csgraph",
34+
"csr",
35+
"csr_array",
36+
"csr_matrix",
37+
"data",
38+
"dia",
39+
"dia_array",
40+
"dia_matrix",
41+
"diags",
42+
"diags_array",
43+
"dok",
44+
"dok_array",
45+
"dok_matrix",
46+
"extract",
47+
"eye",
48+
"eye_array",
49+
"find",
50+
"hstack",
51+
"identity",
52+
"issparse",
53+
"isspmatrix",
54+
"isspmatrix_bsr",
55+
"isspmatrix_coo",
56+
"isspmatrix_csc",
57+
"isspmatrix_csr",
58+
"isspmatrix_dia",
59+
"isspmatrix_dok",
60+
"isspmatrix_lil",
61+
"kron",
62+
"kronsum",
63+
"lil",
64+
"lil_array",
65+
"lil_matrix",
66+
"linalg",
67+
"load_npz",
68+
"rand",
69+
"random",
70+
"random_array",
71+
"save_npz",
72+
"sparray",
73+
"sparsetools",
74+
"spdiags",
75+
"spmatrix",
76+
"sputils",
77+
"tril",
78+
"triu",
79+
"vstack",
80+
]

scipy-stubs/sparse/_base.pyi

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing_extensions import Self, override
1+
from typing import Final
2+
from typing_extensions import Self, TypeIs, override
23

34
from scipy._typing import Untyped
45
from ._matrix import spmatrix as spmatrix
@@ -9,21 +10,21 @@ class SparseWarning(Warning): ...
910
class SparseFormatWarning(SparseWarning): ...
1011
class SparseEfficiencyWarning(SparseWarning): ...
1112

12-
MAXPRINT: int
13+
MAXPRINT: Final = 50
1314

1415
class _spbase:
1516
__array_priority__: float
16-
maxprint: Untyped
17+
maxprint: Final = 50
1718
@property
1819
def ndim(self) -> int: ...
19-
def __init__(self, arg1: Untyped, *, maxprint: Untyped | None = None) -> None: ...
20+
def __init__(self, arg1: Untyped, maxprint: int | None = 50) -> None: ...
2021
@property
2122
def shape(self) -> tuple[int, ...]: ...
2223
def reshape(self, *args: Untyped, **kwargs: Untyped) -> Untyped: ...
2324
def resize(self, shape: tuple[int, int]) -> None: ...
2425
def astype(self, dtype: Untyped, casting: str = "unsafe", copy: bool = True) -> Untyped: ...
2526
def __iter__(self) -> Untyped: ...
26-
def count_nonzero(self, axis: Untyped | None = None) -> int: ...
27+
def count_nonzero(self) -> int: ...
2728
@property
2829
def nnz(self) -> int: ...
2930
@property
@@ -37,17 +38,16 @@ class _spbase:
3738
@property
3839
def imag(self) -> Self: ...
3940
def __bool__(self, /) -> bool: ...
40-
def __len__(self, /) -> int: ...
4141
def asformat(self, format: Untyped, copy: bool = False) -> Untyped: ...
4242
def multiply(self, other: Untyped) -> Untyped: ...
4343
def maximum(self, other: Untyped) -> Untyped: ...
4444
def minimum(self, other: Untyped) -> Untyped: ...
4545
def dot(self, other: Untyped) -> Untyped: ...
4646
def power(self, n: Untyped, dtype: Untyped | None = None) -> Self: ...
4747
@override
48-
def __eq__(self, other: Untyped, /) -> Untyped: ... # type: ignore[override]
48+
def __eq__(self, other: Untyped, /) -> Untyped: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
4949
@override
50-
def __ne__(self, other: Untyped, /) -> Untyped: ... # type: ignore[override]
50+
def __ne__(self, other: Untyped, /) -> Untyped: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]
5151
def __lt__(self, other: Untyped, /) -> Untyped: ...
5252
def __gt__(self, other: Untyped, /) -> Untyped: ...
5353
def __le__(self, other: Untyped, /) -> Untyped: ...
@@ -64,15 +64,7 @@ class _spbase:
6464
def __rmatmul__(self, other: Untyped, /) -> Untyped: ...
6565
def __truediv__(self, other: Untyped, /) -> Untyped: ...
6666
def __div__(self, other: Untyped, /) -> Untyped: ...
67-
def __rtruediv__(self, other: Untyped, /) -> Untyped: ...
68-
def __rdiv__(self, other: Untyped, /) -> Untyped: ...
6967
def __neg__(self, /) -> Self: ...
70-
def __iadd__(self, other: Untyped, /) -> Self: ...
71-
def __isub__(self, other: Untyped, /) -> Self: ...
72-
def __imul__(self, other: Untyped, /) -> Self: ...
73-
def __idiv__(self, other: Untyped, /) -> Self: ...
74-
def __itruediv__(self, other: Untyped, /) -> Self: ...
75-
# NOTE: The modulo was left out for simplicitiy, but might need to be put back in
7668
def __pow__(self, other: Untyped, /) -> Untyped: ...
7769
def transpose(self, axes: Untyped | None = None, copy: bool = False) -> Self: ...
7870
def conjugate(self, copy: bool = True) -> Self: ...
@@ -85,7 +77,7 @@ class _spbase:
8577
def tocoo(self, copy: bool = False) -> Untyped: ...
8678
def tolil(self, copy: bool = False) -> Untyped: ...
8779
def todia(self, copy: bool = False) -> Untyped: ...
88-
def tobsr(self, blocksize: Untyped | None = None, copy: bool = False) -> Untyped: ...
80+
def tobsr(self, blocksize: tuple[int, int] | None = None, copy: bool = False) -> Untyped: ...
8981
def tocsc(self, copy: bool = False) -> Untyped: ...
9082
def copy(self) -> Self: ...
9183
def sum(self, axis: Untyped | None = None, dtype: Untyped | None = None, out: Untyped | None = None) -> Untyped: ...
@@ -96,5 +88,5 @@ class _spbase:
9688

9789
class sparray: ...
9890

99-
def issparse(x: Untyped) -> bool: ...
100-
def isspmatrix(x: Untyped) -> bool: ...
91+
def issparse(x: object) -> TypeIs[_spbase]: ...
92+
def isspmatrix(x: object) -> TypeIs[spmatrix]: ...

scipy-stubs/sparse/_bsr.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class _bsr_base(_cs_matrix, _minmax_mixin):
2121
dtype: npt.DTypeLike | None = None,
2222
copy: bool = False,
2323
blocksize: tuple[int, int] | None = None,
24-
*,
25-
maxprint: Untyped | None = None,
2624
) -> None: ...
2725
@property
2826
def blocksize(self) -> tuple[int, int]: ...

scipy-stubs/sparse/_compressed.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing_extensions import override
22

33
from scipy._typing import Untyped
4+
from ._coo import _coo_base
45
from ._data import _data_matrix, _minmax_mixin
56
from ._index import IndexMixin
67

@@ -16,8 +17,6 @@ class _cs_matrix(_data_matrix, _minmax_mixin, IndexMixin):
1617
shape: Untyped | None = None,
1718
dtype: Untyped | None = None,
1819
copy: bool = False,
19-
*,
20-
maxprint: Untyped | None = None,
2120
) -> None: ...
2221
@override
2322
def count_nonzero(self, axis: Untyped | None = None) -> int: ...
@@ -37,3 +36,5 @@ class _cs_matrix(_data_matrix, _minmax_mixin, IndexMixin):
3736
def prune(self) -> None: ...
3837
@override
3938
def resize(self, *shape: int) -> None: ... # type: ignore[override]
39+
@override
40+
def tocoo(self, copy: bool = True) -> _coo_base: ...

scipy-stubs/sparse/_coo.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class _coo_base(_data_matrix, _minmax_mixin):
1717
shape: Untyped | None = None,
1818
dtype: Untyped | None = None,
1919
copy: bool = False,
20-
*,
21-
maxprint: Untyped | None = None,
2220
) -> None: ...
2321
@property
2422
def row(self) -> Untyped: ...

scipy-stubs/sparse/_csc.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing_extensions import override
2-
31
from scipy._typing import Untyped
42
from ._base import sparray
53
from ._compressed import _cs_matrix

scipy-stubs/sparse/_csr.pyi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ from typing_extensions import override
22

33
from scipy._typing import Untyped
44
from ._base import sparray
5+
from ._bsr import _bsr_base
56
from ._compressed import _cs_matrix
67
from ._matrix import spmatrix
78

89
__all__ = ["csr_array", "csr_matrix", "isspmatrix_csr"]
910

10-
class _csr_base(_cs_matrix): ...
11+
class _csr_base(_cs_matrix):
12+
@override
13+
def tobsr(self, blocksize: tuple[int, int] | None = None, copy: bool = True) -> _bsr_base: ...
14+
1115
class csr_array(_csr_base, sparray): ...
1216
class csr_matrix(spmatrix, _csr_base): ...
1317

scipy-stubs/sparse/_data.pyi

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,46 @@
1+
from typing import Any
2+
from typing_extensions import Never, Self
3+
14
import numpy as np
2-
import numpy.typing as npt
35
from scipy._typing import Untyped
46
from ._base import _spbase
7+
from ._sputils import _ScalarLike
58

69
__all__: list[str] = []
710

811
class _data_matrix(_spbase):
9-
def __init__(self, arg1: Untyped, *, maxprint: Untyped | None = None) -> None: ...
12+
def __init__(self, /, arg1: Untyped) -> None: ...
13+
def __imul__(self, other: _ScalarLike, /) -> Self: ... # type: ignore[misc,override]
14+
def __itruediv__(self, other: _ScalarLike, /) -> Self: ... # type: ignore[misc,override]
1015
@property
11-
def dtype(self) -> np.dtype[np.generic]: ...
16+
def dtype(self, /) -> np.dtype[np.number[Any] | np.bool_]: ...
1217
@dtype.setter
13-
def dtype(self, newtype: npt.DTypeLike) -> None: ...
18+
def dtype(self, newtype: Never, /) -> None: ...
19+
20+
#
21+
def arcsin(self, /) -> Self: ...
22+
def arcsinh(self, /) -> Self: ...
23+
def arctan(self, /) -> Self: ...
24+
def arctanh(self, /) -> Self: ...
25+
def ceil(self, /) -> Self: ...
26+
def deg2rad(self, /) -> Self: ...
27+
def expm1(self, /) -> Self: ...
28+
def floor(self, /) -> Self: ...
29+
def log1p(self, /) -> Self: ...
30+
def rad2deg(self, /) -> Self: ...
31+
def rint(self, /) -> Self: ...
32+
def sign(self, /) -> Self: ...
33+
def sin(self, /) -> Self: ...
34+
def sinh(self, /) -> Self: ...
35+
def sqrt(self, /) -> Self: ...
36+
def tan(self, /) -> Self: ...
37+
def tanh(self, /) -> Self: ...
38+
def trunc(self, /) -> Self: ...
1439

1540
class _minmax_mixin:
16-
def max(self, axis: Untyped | None = None, out: Untyped | None = None, *, explicit: bool = False) -> Untyped: ...
17-
def min(self, axis: Untyped | None = None, out: Untyped | None = None, *, explicit: bool = False) -> Untyped: ...
18-
def nanmax(self, axis: Untyped | None = None, out: Untyped | None = None, *, explicit: bool = False) -> Untyped: ...
19-
def nanmin(self, axis: Untyped | None = None, out: Untyped | None = None, *, explicit: bool = False) -> Untyped: ...
20-
def argmax(self, axis: Untyped | None = None, out: Untyped | None = None, *, explicit: bool = False) -> Untyped: ...
21-
def argmin(self, axis: Untyped | None = None, out: Untyped | None = None, *, explicit: bool = False) -> Untyped: ...
41+
def max(self, axis: int | None = None, out: Untyped | None = None) -> Untyped: ...
42+
def min(self, axis: int | None = None, out: Untyped | None = None) -> Untyped: ...
43+
def nanmax(self, axis: int | None = None, out: Untyped | None = None) -> Untyped: ...
44+
def nanmin(self, axis: int | None = None, out: Untyped | None = None) -> Untyped: ...
45+
def argmax(self, axis: int | None = None, out: Untyped | None = None) -> Untyped: ...
46+
def argmin(self, axis: int | None = None, out: Untyped | None = None) -> Untyped: ...

0 commit comments

Comments
 (0)