numpy_ringbuffer
numpy_ringbuffer copied to clipboard
`__getitem__` does not obey `_left_index` and `_right_index`
Hi @eric-wieser, simple indexing does not work as expected in combination with pop(). E.g.,
r = RingBuffer(capacity=4, dtype=np.int32)
r.extend((1,2,3,4))
r.pop()
print(r[-1])
>>> 4
One would expect to see r[-1] = 3. The reason is that simple indexing does not check whether requested index is within the range between _left_index and _right_index.
The problem here is specifically negative indices, right? Nice catch
It fails with positive indices too. E.g., r[3] returns 4.
Right, so it fails for indices where 0 <= i < len(self) is False. I'll throw a patch together in the next day or two, unless you want to
Yes, that's right. Thanks @eric-wieser , better you do it
Any progress on this bug?
I had a local patch, but the timings ended up way worse as a result of fixing it. I'll try to take another look
Plan to merge?