Skip to content

Commit c2c17c2

Browse files
committedMar 15, 2025·
Removed warning for result of np.unpackbits
1 parent 2ce3f43 commit c2c17c2

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed
 

‎pgvector/bit.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def __init__(self, value):
1515
value = np.asarray(value)
1616

1717
if value.dtype != np.bool:
18-
warn('expected elements to be boolean', stacklevel=2)
18+
# allow result of np.unpackbits
19+
if value.dtype != np.uint8 or np.any(value > 1):
20+
warn('expected elements to be boolean', stacklevel=2)
1921
value = value.astype(bool)
2022

2123
if value.ndim != 1:

‎tests/test_bit.py

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ def test_ndarray(self):
3030
assert Bit(arr).to_list() == [True, False, True]
3131
assert np.array_equal(Bit(arr).to_numpy(), arr)
3232

33+
def test_ndarray_unpackbits(self):
34+
arr = np.unpackbits(np.array([254, 7, 0], dtype=np.uint8))
35+
assert Bit(arr).to_text() == '111111100000011100000000'
36+
3337
def test_ndarray_uint8(self):
3438
arr = np.array([254, 7, 0], dtype=np.uint8)
3539
with pytest.warns(UserWarning, match='expected elements to be boolean'):

0 commit comments

Comments
 (0)
Please sign in to comment.