File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11## 0.5.2 (unreleased)
22
3+ - Fixed error with empty ` Bit ` values
34- Fixed equality for ` HalfVector ` with signed zeros
45
56## 0.5.1 (2026-10-08)
Original file line number Diff line number Diff line change @@ -34,7 +34,11 @@ 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+ # int('', 2) raises, but a zero-length bit string is valid
38+ if length == 0 :
39+ self ._data = b''
40+ else :
41+ self ._data = int (value , 2 ).to_bytes (len (value ) // 8 , byteorder = 'big' )
3842 elif is_ndarray (value ):
3943 import numpy as np
4044
Original file line number Diff line number Diff line change @@ -36,6 +36,22 @@ def test_bytes(self) -> None:
3636 assert Bit (b'\xff \x00 \xf0 ' ).to_text () == '111111110000000011110000'
3737 assert Bit (b'\xfe \x07 \x00 ' ).to_text () == '111111100000011100000000'
3838
39+ def test_empty (self ) -> None :
40+ bit = Bit (b'' )
41+ assert bit .to_list () == []
42+ assert bit .to_text () == ''
43+ assert bit .to_binary () == pack ('>i' , 0 )
44+ assert Bit ('' ) == bit
45+ assert Bit ([]) == bit
46+ assert Bit .from_text ('' ) == bit
47+ assert Bit .from_text (bit .to_text ()) == bit
48+ assert Bit .from_binary (bit .to_binary ()) == bit
49+ assert bit != Bit ('0' )
50+ assert bit != Bit (b'\x00 ' )
51+ if np is not None :
52+ assert np .array_equal (bit .to_numpy (), np .array ([], dtype = bool ))
53+ assert Bit (np .array ([], dtype = bool )) == bit
54+
3955 def test_ndarray (self ) -> None :
4056 if np is None :
4157 pytest .skip ('NumPy required' )
You can’t perform that action at this time.
0 commit comments