Skip to content

Commit 3c1d196

Browse files
committed
Rename alignment arguments to align_to
Both the `MovingWindow` and the `OrderedRingBuffer` are updated to use `align_to` as the argument to set the alignment. This is to make it more consistent with the resampler. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 1957d1b commit 3c1d196

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
Note that the parameter `sampling_period` has been renamed to `input_sampling_period` to better distinguish it from the sampling period parameter in the `resampler_config`.
5454

55-
* Use the `UNIX_EPOCH` as the default alignment.
55+
* Rename the constructor argument `window_alignment` to `align_to` and change the default to `UNIX_EPOCH`. This is to make it more consistent with the `ResamplerConfig`.
5656

5757
* `Resampler`
5858

src/frequenz/sdk/timeseries/_moving_window.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ class MovingWindow:
4040
a fixed defined point in time. Since the moving nature of the window, the
4141
date of the first and the last element are constantly changing and therefore
4242
the point in time that defines the alignment can be outside of the time window.
43-
Modulo arithmetic is used to move the `window_alignment` timestamp into the
44-
latest window.
45-
If for example the `window_alignment` parameter is set to
43+
Modulo arithmetic is used to move the `align_to` timestamp into the latest
44+
window.
45+
46+
If for example the `align_to` parameter is set to
4647
`datetime(1, 1, 1, tzinfo=timezone.utc)` and the window size is bigger than
4748
one day then the first element will always be aligned to the midnight.
4849
For further information see also the
@@ -107,7 +108,7 @@ def __init__( # pylint: disable=too-many-arguments
107108
resampled_data_recv: Receiver[Sample],
108109
input_sampling_period: timedelta,
109110
resampler_config: ResamplerConfig | None = None,
110-
window_alignment: datetime = UNIX_EPOCH,
111+
align_to: datetime = UNIX_EPOCH,
111112
) -> None:
112113
"""
113114
Initialize the MovingWindow.
@@ -122,7 +123,7 @@ def __init__( # pylint: disable=too-many-arguments
122123
given sampling period.
123124
input_sampling_period: The time interval between consecutive input samples.
124125
resampler_config: The resampler configuration in case resampling is required.
125-
window_alignment: A datetime object that defines a point in time to which
126+
align_to: A datetime object that defines a point in time to which
126127
the window is aligned to modulo window size. For further
127128
information, consult the class level documentation.
128129
@@ -156,7 +157,7 @@ def __init__( # pylint: disable=too-many-arguments
156157
self._buffer = OrderedRingBuffer(
157158
np.empty(shape=num_samples, dtype=float),
158159
sampling_period=sampling,
159-
time_index_alignment=window_alignment,
160+
align_to=align_to,
160161
)
161162

162163
if self._resampler:

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ def __init__(
5454
self,
5555
buffer: FloatArray,
5656
sampling_period: timedelta,
57-
time_index_alignment: datetime = UNIX_EPOCH,
57+
align_to: datetime = UNIX_EPOCH,
5858
) -> None:
5959
"""Initialize the time aware ringbuffer.
6060
6161
Args:
6262
buffer: Instance of a buffer container to use internally.
6363
sampling_period: Timedelta of the desired sampling period.
64-
time_index_alignment: Arbitrary point in time used to align
64+
align_to: Arbitrary point in time used to align
6565
timestamped data with the index position in the buffer.
6666
Used to make the data stored in the buffer align with the
6767
beginning and end of the buffer borders.
6868
69-
For example, if the `time_index_alignment` is set to
69+
For example, if the `align_to` is set to
7070
"0001-01-01 12:00:00", and the `sampling_period` is set to
7171
1 hour and the length of the buffer is 24, then the data
7272
stored in the buffer could correspond to the time range from
@@ -77,7 +77,7 @@ def __init__(
7777

7878
self._buffer: FloatArray = buffer
7979
self._sampling_period: timedelta = sampling_period
80-
self._time_index_alignment: datetime = time_index_alignment
80+
self._time_index_alignment: datetime = align_to
8181

8282
self._gaps: list[Gap] = []
8383
self._datetime_newest: datetime = self._DATETIME_MIN
@@ -201,7 +201,7 @@ def window(
201201
* The force_copy parameter was set to True (default False).
202202
203203
The first case can be avoided by using the appropriate
204-
time_index_alignment value in the constructor so that the data lines up
204+
`align_to` value in the constructor so that the data lines up
205205
with the start/end of the buffer.
206206
207207
This means, if the caller needs to modify the data to account for

tests/timeseries/test_ringbuffer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def test_len_ringbuffer_samples_fit_buffer_size() -> None:
266266
buffer = OrderedRingBuffer(
267267
np.empty(shape=len(test_samples), dtype=float),
268268
sampling_period=timedelta(seconds=1),
269-
time_index_alignment=datetime(1, 1, 1, tzinfo=timezone.utc),
269+
align_to=datetime(1, 1, 1, tzinfo=timezone.utc),
270270
)
271271

272272
start_ts: datetime = datetime(2023, 1, 1, tzinfo=timezone.utc)
@@ -294,7 +294,7 @@ def test_len_ringbuffer_samples_overwrite_buffer() -> None:
294294
buffer = OrderedRingBuffer(
295295
np.empty(shape=half_buffer_size, dtype=float),
296296
sampling_period=timedelta(seconds=1),
297-
time_index_alignment=datetime(1, 1, 1, tzinfo=timezone.utc),
297+
align_to=datetime(1, 1, 1, tzinfo=timezone.utc),
298298
)
299299

300300
start_ts: datetime = datetime(2023, 1, 1, tzinfo=timezone.utc)
@@ -316,10 +316,10 @@ def test_ringbuffer_empty_buffer() -> None:
316316
OrderedRingBuffer(
317317
empty_np_buffer,
318318
sampling_period=timedelta(seconds=1),
319-
time_index_alignment=datetime(1, 1, 1),
319+
align_to=datetime(1, 1, 1),
320320
)
321321
OrderedRingBuffer(
322322
empty_list_buffer,
323323
sampling_period=timedelta(seconds=1),
324-
time_index_alignment=datetime(1, 1, 1),
324+
align_to=datetime(1, 1, 1),
325325
)

0 commit comments

Comments
 (0)