Skip to content

Commit 09c588e

Browse files
committed
Fix the resampler handling of output zeros
A bug made the resampler interpret output zero values as `None`, producing wrong resampled values when the result of the resampling function is zero. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 7c9c471 commit 09c588e

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
## Bug Fixes
44

5-
- The resampler now properly handles zero values.
5+
- The resampler now properly handles sending zero values.
66

7-
A bug made the resampler interpret zero values as `None` (or NaN), producing wrong resampled averages.
8-
9-
In extreme cases where a long stream of zero values longer than the buffer size was sent, the resampler would just start producing `None` values.
7+
A bug made the resampler interpret zero values as `None` when generating new samples, so if the result of the resampling is zero, the resampler would just produce `None` values.

tests/timeseries/test_resampling.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ async def test_resampling_with_one_window(
617617
#
618618
# t(s) 0 1 2 2.5 3 4
619619
# |----------|----------R----|-----|----------R-----> (no more samples)
620-
# value 5.0 12.0 2.0 4.0 5.0
620+
# value 5.0 12.0 0.0 4.0 5.0
621621
#
622622
# R = resampling is done
623623

@@ -647,7 +647,7 @@ async def test_resampling_with_one_window(
647647
resampling_fun_mock.reset_mock()
648648

649649
# Second resampling run
650-
sample2_5s = Sample(timestamp + timedelta(seconds=2.5), value=Quantity(2.0))
650+
sample2_5s = Sample(timestamp + timedelta(seconds=2.5), value=Quantity.zero())
651651
sample3s = Sample(timestamp + timedelta(seconds=3), value=Quantity(4.0))
652652
sample4s = Sample(timestamp + timedelta(seconds=4), value=Quantity(5.0))
653653
await source_sender.send(sample2_5s)
@@ -1242,8 +1242,8 @@ async def test_resampling_all_zeros(
12421242
# R = resampling is done
12431243

12441244
# Send a few samples and run a resample tick, advancing the fake time by one period
1245-
sample0s = Sample(timestamp, value=Quantity(0.0))
1246-
sample1s = Sample(timestamp + timedelta(seconds=1), value=Quantity(0.0))
1245+
sample0s = Sample(timestamp, value=Quantity.zero())
1246+
sample1s = Sample(timestamp + timedelta(seconds=1), value=Quantity.zero())
12471247
await source_sender.send(sample0s)
12481248
await source_sender.send(sample1s)
12491249
await _advance_time(fake_time, resampling_period_s)
@@ -1267,9 +1267,9 @@ async def test_resampling_all_zeros(
12671267
resampling_fun_mock.reset_mock()
12681268

12691269
# Second resampling run
1270-
sample2_5s = Sample(timestamp + timedelta(seconds=2.5), value=Quantity(0.0))
1271-
sample3s = Sample(timestamp + timedelta(seconds=3), value=Quantity(0.0))
1272-
sample4s = Sample(timestamp + timedelta(seconds=4), value=Quantity(0.0))
1270+
sample2_5s = Sample(timestamp + timedelta(seconds=2.5), value=Quantity.zero())
1271+
sample3s = Sample(timestamp + timedelta(seconds=3), value=Quantity.zero())
1272+
sample4s = Sample(timestamp + timedelta(seconds=4), value=Quantity.zero())
12731273
await source_sender.send(sample2_5s)
12741274
await source_sender.send(sample3s)
12751275
await source_sender.send(sample4s)

0 commit comments

Comments
 (0)