Skip to content

Commit

Permalink
Adding most of the mutating methods from BitArray (but now return new…
Browse files Browse the repository at this point in the history
… Bits).

Adding tests from test_bitstream.py.
  • Loading branch information
scott-griffiths committed Jun 12, 2024
1 parent ac09f13 commit 90544e8
Show file tree
Hide file tree
Showing 8 changed files with 2,005 additions and 60 deletions.
2 changes: 1 addition & 1 deletion bitformat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def bool_bits2chars(_: Literal[1]):
allowed_lengths=(16, 32, 64), description="a big-endian floating point number"),
# Other known length types
DtypeDefinition('bits', Bits._setbits, Bits._getbits, Bits, False, bits_bits2chars,
description="a bitstring object"),
description="a Bits object"),
DtypeDefinition('bool', Bits._setbool, Bits._getbool, bool, False, bool_bits2chars,
allowed_lengths=(1,), description="a bool (True or False)"),
DtypeDefinition('bytes', Bits._setbytes, Bits._getbytes, bytes, False, bytes_bits2chars,
Expand Down
2 changes: 1 addition & 1 deletion bitformat/array_.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def _apply_bitwise_op_to_all_elements_inplace(self, op, value: BitsType) -> Arra
"""Apply op with value to each element of the Array as an unsigned integer in place."""
value = Bits._create_from_bitstype(value)
if len(value) != self._dtype.length:
raise ValueError(f"Bitwise op needs a bitstring of length {self._dtype.length} to match format {self._dtype}.")
raise ValueError(f"Bitwise op needs a Bits of length {self._dtype.length} to match format {self._dtype}.")
for start in range(0, len(self) * self._dtype.length, self._dtype.length):
self._data.setitem(slice(start, start + self._dtype.length), op(self._data.getslice(start, start + self._dtype.length), value._bitstore))
return self
Expand Down
Loading

0 comments on commit 90544e8

Please sign in to comment.