Skip to content

Commit 5f909bc

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 dfb2875 commit 5f909bc

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
@@ -266,7 +266,6 @@ def window(
266266
267267
Will return a copy in the following cases:
268268
* The requested time period is crossing the start/end of the buffer.
269-
* The requested time period contains missing entries.
270269
* The force_copy parameter was set to True (default False).
271270
272271
The first case can be avoided by using the appropriate
@@ -308,10 +307,7 @@ def window(
308307
assert False, f"Unknown _buffer type: {type(self._buffer)}"
309308
return self._buffer[start_index:]
310309

311-
# Return a copy if there are none-values in the data
312-
if force_copy or any(
313-
map(lambda gap: gap.contains(start) or gap.contains(end), self._gaps)
314-
):
310+
if force_copy:
315311
return deepcopy(self[start_index:end_index])
316312

317313
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
@@ -519,6 +519,6 @@ def test_window() -> None:
519519
assert [0, np.nan, 2] == list(win)
520520
buffer._buffer[1] = 1 # pylint: disable=protected-access
521521
# Test whether the window is a view or a copy
522-
assert [0, 1, 2] == list(win) # NB: second element should be NaN according to docs
522+
assert [0, 1, 2] == list(win)
523523
win = buffer.window(dt(0), dt(3), force_copy=False)
524524
assert [0, 1, 2] == list(win)

0 commit comments

Comments
 (0)