Skip to content

Commit ac1a543

Browse files
committed
Improved validation for Bit constructor
1 parent 7846622 commit ac1a543

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Diff for: pgvector/bit.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ def __init__(self, value):
1313
elif value.dtype != np.bool:
1414
raise ValueError('expected dtype to be bool or uint8')
1515
else:
16-
value = np.asarray(value, dtype=bool)
16+
value = np.asarray(value)
17+
if value.dtype != np.bool:
18+
raise ValueError('expected dtype to be bool')
1719

1820
if value.ndim != 1:
1921
raise ValueError('expected ndim to be 1')

Diff for: tests/test_bit.py

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ class TestBit:
77
def test_list(self):
88
assert Bit([True, False, True]).to_list() == [True, False, True]
99

10+
def test_list_int(self):
11+
with pytest.raises(ValueError) as error:
12+
Bit([254, 7, 0])
13+
assert str(error.value) == 'expected dtype to be bool'
14+
1015
def test_tuple(self):
1116
assert Bit((True, False, True)).to_list() == [True, False, True]
1217

0 commit comments

Comments
 (0)