Skip to content

Commit 2915a59

Browse files
Fixed error with Bit constructor and empty strings - fixes #165 and resolves #166
Co-authored-by: Zaakir Hussain <ZaakirHussain5@users.noreply.github.com>
1 parent 8cef6e4 commit 2915a59

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 0.5.2 (unreleased)
22

3+
- Fixed error with `Bit` constructor and empty strings
34
- Fixed equality for `HalfVector` with signed zeros
45

56
## 0.5.1 (2026-10-08)

‎pgvector/bit.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ def __init__(
3434
value += '0' * (8 - (length % 8))
3535

3636
self._length = length
37-
self._data = int(value, 2).to_bytes(len(value) // 8, byteorder='big')
37+
if length > 0:
38+
self._data = int(value, 2).to_bytes(len(value) // 8, byteorder='big')
39+
else:
40+
self._data = b''
3841
elif is_ndarray(value):
3942
import numpy as np
4043

‎tests/test_bit.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def test_list_list(self) -> None:
2727
def test_str(self) -> None:
2828
assert Bit('101').to_list() == [True, False, True]
2929

30+
def test_str_empty(self) -> None:
31+
assert Bit('').to_list() == []
32+
3033
def test_str_two(self) -> None:
3134
with pytest.raises(ValueError) as error:
3235
Bit('201')

0 commit comments

Comments
 (0)