Skip to content

Commit 9409d64

Browse files
committed
Improved typing [skip ci]
1 parent a6465d1 commit 9409d64

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

pgvector/sparsevec.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22
from struct import pack, unpack_from
3-
from typing import TYPE_CHECKING, Final, overload
3+
from typing import TYPE_CHECKING, Final, cast, overload
44
from ._utils import is_sparse_array, ndarray
55

66
if TYPE_CHECKING:
@@ -98,10 +98,11 @@ def _from_dict(self, d: dict[int, float], dim: int) -> None:
9898
def _from_sparse(self, arr: sparray | spmatrix) -> None:
9999
value: coo_array | coo_matrix = arr.tocoo() # type: ignore
100100

101-
if value.ndim == 1:
102-
self._dim = value.shape[0] # type: ignore
103-
elif value.ndim == 2 and value.shape[0] == 1: # type: ignore
104-
self._dim = value.shape[1] # type: ignore
101+
shape = cast(tuple[int], value.shape)
102+
if len(shape) == 1:
103+
self._dim = shape[0]
104+
elif len(shape) == 2 and shape[0] == 1:
105+
self._dim = shape[1]
105106
else:
106107
raise ValueError('expected ndim to be 1')
107108

0 commit comments

Comments
 (0)