Skip to content

Commit 46ebe82

Browse files
committed
🧪 sparse: add type-tests for lil_array and lil_matrix
1 parent 5ed42d4 commit 46ebe82

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

‎tests/sparse/test_lil.pyi‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# regression tests for https://github.com/scipy/scipy-stubs/issues/817
2+
3+
from typing import assert_type
4+
5+
import numpy as np
6+
7+
from ._types import ScalarType, lil_arr, lil_mat
8+
from scipy.sparse import lil_array, lil_matrix
9+
10+
dtype: np.dtype[ScalarType]
11+
12+
shape2: tuple[int, int]
13+
14+
data2: np.ndarray[tuple[int, int], np.dtype[ScalarType]]
15+
16+
###
17+
# CSC matrix constructor
18+
# ruff: noqa: ERA001
19+
20+
# lil_matrix(D)
21+
assert_type(lil_matrix(data2), lil_matrix[ScalarType])
22+
assert_type(lil_matrix(data2, dtype=dtype), lil_matrix[ScalarType])
23+
assert_type(lil_matrix(data2, dtype=bool), lil_matrix[np.bool_])
24+
assert_type(lil_matrix(data2, dtype=int), lil_matrix[np.int_])
25+
assert_type(lil_matrix(data2, dtype=float), lil_matrix[np.float64])
26+
assert_type(lil_matrix(data2, dtype=complex), lil_matrix[np.complex128])
27+
28+
# lil_matrix(S)
29+
assert_type(lil_matrix(lil_arr), lil_matrix[ScalarType])
30+
assert_type(lil_matrix(lil_mat), lil_matrix[ScalarType])
31+
32+
# lil_matrix((M, N), [dtype])
33+
assert_type(lil_matrix(shape2), lil_matrix[np.float64])
34+
assert_type(lil_matrix(shape2, dtype=dtype), lil_matrix[ScalarType])
35+
assert_type(lil_matrix(shape2, dtype=bool), lil_matrix[np.bool_])
36+
assert_type(lil_matrix(shape2, dtype=int), lil_matrix[np.int_])
37+
assert_type(lil_matrix(shape2, dtype=float), lil_matrix[np.float64])
38+
assert_type(lil_matrix(shape2, dtype=complex), lil_matrix[np.complex128])
39+
40+
###
41+
# CSC array constructor
42+
43+
# lil_array(D)
44+
assert_type(lil_array(data2), lil_array[ScalarType])
45+
assert_type(lil_array(data2, dtype=dtype), lil_array[ScalarType])
46+
assert_type(lil_array(data2, dtype=bool), lil_array[np.bool_])
47+
assert_type(lil_array(data2, dtype=int), lil_array[np.int_])
48+
assert_type(lil_array(data2, dtype=float), lil_array[np.float64])
49+
assert_type(lil_array(data2, dtype=complex), lil_array[np.complex128])
50+
51+
# lil_array(S)
52+
assert_type(lil_array(lil_arr), lil_array[ScalarType])
53+
assert_type(lil_array(lil_mat), lil_array[ScalarType])
54+
55+
# lil_array((M, N), [dtype])
56+
assert_type(lil_array(shape2), lil_array[np.float64])
57+
assert_type(lil_array(shape2, dtype=dtype), lil_array[ScalarType])
58+
assert_type(lil_array(shape2, dtype=bool), lil_array[np.bool_])
59+
assert_type(lil_array(shape2, dtype=int), lil_array[np.int_])
60+
assert_type(lil_array(shape2, dtype=float), lil_array[np.float64])
61+
assert_type(lil_array(shape2, dtype=complex), lil_array[np.complex128])

0 commit comments

Comments
 (0)