Skip to content

Commit 98c602a

Browse files
committed
Improve typing while calculating the new buffer len
`new_buffer_len` has `float` type, which is weird, even if it is handled properly and converted when assigning to the buffer's `maxlen`. This commit makes `new_buffer_len` always an `int` to make the intentions more clear. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 9ba4824 commit 98c602a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/frequenz/sdk/timeseries/_resampling.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -589,24 +589,24 @@ def _update_buffer_len(self) -> bool:
589589

590590
config = self._config
591591

592-
# If we are upsampling, one sample could be enough for back-filling, but
593-
# we store max_data_age_in_periods for input periods, so resampling
594-
# functions can do more complex inter/extrapolation if they need to.
595-
if input_sampling_period > config.resampling_period:
596-
new_buffer_len = (
597-
input_sampling_period.total_seconds() * config.max_data_age_in_periods
598-
)
599-
# If we are upsampling, we want a buffer that can hold
600-
# max_data_age_in_periods * resampling_period of data, and we
601-
# one sample every input_sampling_period.
602-
else:
603-
new_buffer_len = (
592+
new_buffer_len = math.ceil(
593+
# If we are upsampling, one sample could be enough for
594+
# back-filling, but we store max_data_age_in_periods for input
595+
# periods, so resampling functions can do more complex
596+
# inter/extrapolation if they need to.
597+
(input_sampling_period.total_seconds() * config.max_data_age_in_periods)
598+
if input_sampling_period > config.resampling_period
599+
# If we are downsampling, we want a buffer that can hold
600+
# max_data_age_in_periods * resampling_period of data, and we one
601+
# sample every input_sampling_period.
602+
else (
604603
config.resampling_period.total_seconds()
605604
/ input_sampling_period.total_seconds()
606605
* config.max_data_age_in_periods
607606
)
607+
)
608608

609-
new_buffer_len = max(1, math.ceil(new_buffer_len))
609+
new_buffer_len = max(1, new_buffer_len)
610610
if new_buffer_len > config.max_buffer_len:
611611
_logger.error(
612612
"The new buffer length (%s) for timeseries %s is too big, using %s instead",

0 commit comments

Comments
 (0)