Skip to content

Commit 3e7d56b

Browse files
committed
Improved typing
1 parent 4bcf31c commit 3e7d56b

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

pgvector/sparsevec.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
pass
99

1010
try:
11-
from scipy.sparse import sparray, spmatrix
11+
from scipy.sparse import sparray, spmatrix, coo_array, coo_matrix
1212
SCIPY_AVAILABLE = True
1313
except ImportError:
1414
SCIPY_AVAILABLE = False
@@ -34,7 +34,7 @@ def __init__(self, value: dict[int, float] | list[float] | np.ndarray[tuple[int]
3434
if dimensions is not NO_DEFAULT:
3535
raise ValueError('extra argument')
3636

37-
self._from_sparse(value)
37+
self._from_sparse(value) # type: ignore
3838
elif isinstance(value, dict):
3939
if dimensions is NO_DEFAULT:
4040
raise ValueError('missing dimensions')
@@ -97,13 +97,13 @@ def _from_dict(self, d: dict[int, float], dim: int) -> None:
9797
self._indices = [int(v[0]) for v in elements]
9898
self._values = [float(v[1]) for v in elements]
9999

100-
def _from_sparse(self, value: Any) -> None:
101-
value = value.tocoo()
100+
def _from_sparse(self, arr: sparray | spmatrix) -> None:
101+
value: coo_array | coo_matrix = arr.tocoo() # type: ignore
102102

103103
if value.ndim == 1:
104-
self._dim = value.shape[0]
105-
elif value.ndim == 2 and value.shape[0] == 1:
106-
self._dim = value.shape[1]
104+
self._dim = value.shape[0] # type: ignore
105+
elif value.ndim == 2 and value.shape[0] == 1: # type: ignore
106+
self._dim = value.shape[1] # type: ignore
107107
else:
108108
raise ValueError('expected ndim to be 1')
109109

0 commit comments

Comments
 (0)