Skip to content

Commit ac9fd53

Browse files
committed
Improved Bit constructor for uint8 NumPy arrays
1 parent 1676e3e commit ac9fd53

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

pgvector/bit.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@ def __init__(self, value):
77
if isinstance(value, str):
88
self._value = self.from_text(value)._value
99
else:
10-
# TODO change in 0.4.0
1110
# TODO raise if dtype not bool or uint8
12-
# if isinstance(value, np.ndarray) and value.dtype == np.uint8:
13-
# value = np.unpackbits(value)
14-
# else:
15-
# value = np.asarray(value, dtype=bool)
16-
17-
value = np.asarray(value, dtype=bool)
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)
1815

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

tests/test_bit.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ def test_str(self):
1515

1616
def test_ndarray_uint8(self):
1717
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'
18+
assert Bit(arr).to_text() == '111111100000011100000000'
2119

2220
def test_ndarray_same_object(self):
2321
arr = np.array([True, False, True])

0 commit comments

Comments
 (0)