-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix single element access for moving window #672
Conversation
Blocking since based on #668. |
Ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So at()
is basically __getitem__()
limited to one element (so no slices)? Any reason to keep it as a public method? For me it adds a bit of confusion, the same I'm wondering what's the difference with __getitem__()
, other users could have the same doubt.
@@ -241,6 +241,43 @@ def capacity(self) -> int: | |||
""" | |||
return self._buffer.maxlen | |||
|
|||
def at(self, key: int | datetime) -> float: # pylint: disable=invalid-name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually hate this check failing because names are short. Fortunately is going away in pylint
3.
We could disable it now by customizing the name regexes, but I'm not sure it is worth it.
Yes, there is
The reason I made it public is that it could also support extra arguments such as filling missing values like for the window method (stub here: #669). |
OK, that makes sense, but then I would add a note in both cross-linking and quickly mentioning the differences. |
Updated @llucax |
""" | ||
Return the sample at the given index or timestamp. | ||
|
||
In contrast to the `window` method, which expects a slice as argument, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional, as I will still go through the code docs and improve them, but mentioning this so people get used to use cross references.
In contrast to the `window` method, which expects a slice as argument, | |
In contrast to the [`window`][frequenz.sdk.timeseries.MovingWindow.window] method, which expects a slice as argument, |
More tests for single element access of the moving window are added including tests that indicate bugs which should be fixed in follow-up commits. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
This method implements corrected access of single elements in the moving window. Similar to its `window` counterpart for slices, in future it could provide additional features such as replacing missing values. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
The incomplete implementation of single element access in the getitem magic is replaced by using the `at` method. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Updated @llucax |
This brings full support for single element access in moving windows either via integer or datetime indices including bug fixes.