Skip to content

Commit

Permalink
Added test for Bit constructor with uint8
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jul 17, 2024
1 parent e77ee13 commit 4498caa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pgvector/utils/bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ def __init__(self, value):
if isinstance(value, str):
self._value = self.from_text(value)._value
else:
# TODO use np.unpackbits for uint8 array
# TODO change in 0.4.0
# if isinstance(value, np.ndarray) and value.dtype == np.uint8:
# value = np.unpackbits(value)
# else:
# value = np.asarray(value, dtype=bool)

value = np.asarray(value, dtype=bool)

if value.ndim != 1:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def test_tuple(self):
def test_str(self):
assert Bit('101').to_list() == [True, False, True]

def test_ndarray_uint8(self):
arr = np.array([254, 7, 0], dtype=np.uint8)
# TODO change in 0.4.0
# assert Bit(arr).to_text() == '111111100000011100000000'
assert Bit(arr).to_text() == '110'

def test_ndarray_same_object(self):
arr = np.array([True, False, True])
assert Bit(arr).to_list() == [True, False, True]
Expand Down

0 comments on commit 4498caa

Please sign in to comment.