Skip to content

Commit ada4221

Browse files
committed
Do not force copy on Nones in ring buffer window
The functionality was not working as intended. Moreover the decision whether to enforce a copy or not should be left to the user even if the data contains None values. Signed-off-by: cwasicki <[email protected]>
1 parent f01f37e commit ada4221

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

src/frequenz/sdk/timeseries/_ringbuffer/buffer.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ def window(
219219
220220
Will return a copy in the following cases:
221221
* The requested time period is crossing the start/end of the buffer.
222-
* The requested time period contains missing entries.
223222
* The force_copy parameter was set to True (default False).
224223
225224
The first case can be avoided by using the appropriate
@@ -261,10 +260,7 @@ def window(
261260
assert False, f"Unknown _buffer type: {type(self._buffer)}"
262261
return self._buffer[start_index:]
263262

264-
# Return a copy if there are none-values in the data
265-
if force_copy or any(
266-
map(lambda gap: gap.contains(start) or gap.contains(end), self._gaps)
267-
):
263+
if force_copy:
268264
return deepcopy(self[start_index:end_index])
269265

270266
return self[start_index:end_index]

tests/timeseries/test_ringbuffer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,6 @@ def test_window() -> None:
449449
assert [0, np.nan, 2] == list(win)
450450
buffer._buffer[1] = 1 # pylint: disable=protected-access
451451
# Test whether the window is a view or a copy
452-
assert [0, 1, 2] == list(win) # NB: second element should be NaN according to docs
452+
assert [0, 1, 2] == list(win)
453453
win = buffer.window(dt(0), dt(3), force_copy=False)
454454
assert [0, 1, 2] == list(win)

0 commit comments

Comments
 (0)