numpy_ringbuffer icon indicating copy to clipboard operation
numpy_ringbuffer copied to clipboard

`__getitem__` does not obey `_left_index` and `_right_index`

Open b4be1 opened this issue 8 years ago • 7 comments

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.

b4be1 avatar Jun 30 '17 11:06 b4be1

The problem here is specifically negative indices, right? Nice catch

eric-wieser avatar Jun 30 '17 11:06 eric-wieser

It fails with positive indices too. E.g., r[3] returns 4.

b4be1 avatar Jun 30 '17 11:06 b4be1

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

eric-wieser avatar Jun 30 '17 11:06 eric-wieser

Yes, that's right. Thanks @eric-wieser , better you do it

b4be1 avatar Jun 30 '17 11:06 b4be1

Any progress on this bug?

xgdgsc avatar Nov 19 '17 12:11 xgdgsc

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

eric-wieser avatar Nov 21 '17 07:11 eric-wieser

Plan to merge?

Alexander-Shukaev avatar Nov 17 '18 11:11 Alexander-Shukaev