bitformat replacing bitstring functionality? #3
Closed
scott-griffiths
started this conversation in
Ideas
Replies: 1 comment
-
Unfortunately Would it be crazy to use
I'm tempted to keep |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There's a temptation to make bitformat a bit of a re-write of bitstring in terms of the user interface. A lot of the design choices in bitstring were taken over 15 years ago, with Python 2.4 in mind. I'd make quite a few different choices if designing it now.
This doesn't need to be a great deal of work, as for now at least there's no need to rewrite the functionality, I can just make a new API that calls the bitstring methods. Later it might need reworking for efficiency of course.
These are just suggestions so that they can be thought about, but need to get something done in writing first:
New class BitField. Perhaps this has a better name later, but I don't want to call it Bits as that would be confusing. It is however basically a replacement for bitstring.Bits.
BitField
s.bin
uses.to('bin')
, or to someDtype
.BitField
.BitField
, instead just make a class that hasBitField
and apos
members.Methods
Included the same as bitstring.Bits:
Not included:
Special methods
Probably include the same as bitstring.Bits (?)
Methods from bitstring.BitArray:
These all need new signatures to return a BitField:
Not included:
New methods
BitField.to(t: str | Dtype, /) -> Any
This replaces
tobytes()
withto('bytes')
and also allowsto('bin')
etc. to replace the getter properties.BitField.from(t: str | Dtype, value: Any, /) -> BitField
Creates new BitField to replace the setter properties. Possibly don't allow the
t
to be a value such asu12=4
and instead require it to only specify the type. This makes the interface clearer. You can now also dox = BitField.from('bytes', b)
which makesx = BitField.frombytes(b)
a bit redundant. Also I think I likex = BitField.from('str', s)
instead ofx = BitField.fromstring(s)
.MVP
__getitem__
(Note: do we want to return aBitField
or a bool for a single item)That's a shorter list than I expected!
Other stuff
.from('str', s)
would be using the new bitformat strings. So disallow things like the'*'
multiplier etc.from
andto
methods could accept array formats. Sox = BitField.from('[bool; 3]', [True, False, False])
orb.to('[u8;5]')
. This could be quite cool. Alsob.to('[u8]')
without a length would be useful.Could this replace all the bitstring.Array functionality? No, as the BitField doesn't know its Dtype. But a lot could still be done. And a
BitField
+Dtype
can do just about everything.These two I think are equivalent:
bitfield.to(dtype) -> Any
dtype.parse(bitfield) -> Any
As are these:
BitField.from(dtype, value) -> BitField
dtype.build(value) -> BitField
I think they're both reasonable to have, but they can essentially share one implementation.
Beta Was this translation helpful? Give feedback.
All reactions