Skip to content

Commit d858fcd

Browse files
committed
Fixed from_sparse method for scipy < 1.13
1 parent 550aa64 commit d858fcd

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pgvector/utils/sparsevec.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@ def from_dict(cls, d, dim):
2424
def from_sparse(cls, value):
2525
value = value.tocoo()
2626

27-
if value.ndim != 1:
27+
if value.ndim == 1:
28+
dim = value.shape[0]
29+
elif value.ndim == 2 and value.shape[0] == 1:
30+
dim = value.shape[1]
31+
else:
2832
raise ValueError('expected ndim to be 1')
2933

30-
dim = value.shape[0]
31-
indices = value.coords[0].tolist()
34+
if hasattr(value, 'coords'):
35+
# scipy 1.13+
36+
indices = value.coords[0].tolist()
37+
else:
38+
indices = value.col.tolist()
3239
values = value.data.tolist()
3340
return cls(dim, indices, values)
3441

0 commit comments

Comments
 (0)