Skip to content

Commit 4498caa

Browse files
committed
Added test for Bit constructor with uint8
1 parent e77ee13 commit 4498caa

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pgvector/utils/bit.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ def __init__(self, value):
77
if isinstance(value, str):
88
self._value = self.from_text(value)._value
99
else:
10-
# TODO use np.unpackbits for uint8 array
10+
# TODO change in 0.4.0
11+
# if isinstance(value, np.ndarray) and value.dtype == np.uint8:
12+
# value = np.unpackbits(value)
13+
# else:
14+
# value = np.asarray(value, dtype=bool)
15+
1116
value = np.asarray(value, dtype=bool)
1217

1318
if value.ndim != 1:

tests/test_bit.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ def test_tuple(self):
1313
def test_str(self):
1414
assert Bit('101').to_list() == [True, False, True]
1515

16+
def test_ndarray_uint8(self):
17+
arr = np.array([254, 7, 0], dtype=np.uint8)
18+
# TODO change in 0.4.0
19+
# assert Bit(arr).to_text() == '111111100000011100000000'
20+
assert Bit(arr).to_text() == '110'
21+
1622
def test_ndarray_same_object(self):
1723
arr = np.array([True, False, True])
1824
assert Bit(arr).to_list() == [True, False, True]

0 commit comments

Comments
 (0)