Skip to content

Conversation

@cwasicki
Copy link
Collaborator

@cwasicki cwasicki commented Sep 4, 2023

This PR introduces several copy-related updates to the ring buffer window functionality

Changes:

  • Default Copy Behavior: Changed the default behavior to copy data in the ring buffer window. This is to prioritize data integrity over performance, which is a minor concern for most expected use-cases. Made force_copy as a keyword argument.
  • Moved the logic for extracting wrapped buffers into a separate method to fix a bug and allow for better testing and future maintainability.
  • Handling None Values: Fixed an issue where None values were being forcibly copied in the ring buffer window. The decision to enforce a copy is now left to the user, even when the data contains None values.
  • Test Coverage: Added tests for the window method in the ring buffer, including tests for expected copy behavior on missing values.
  • Fix to return an empty array in case start = end in ring buffer window.
  • Expose restricted ring buffer window by moving window.

Part of #214

@cwasicki cwasicki requested a review from a team as a code owner September 4, 2023 16:55
@github-actions github-actions bot added part:tests Affects the unit, integration and performance (benchmarks) tests part:data-pipeline Affects the data pipeline labels Sep 4, 2023
@cwasicki cwasicki force-pushed the rbuffer-copy branch 2 times, most recently from 74ba702 to 1f914df Compare September 4, 2023 19:08
@github-actions github-actions bot added the part:docs Affects the documentation label Sep 4, 2023
@cwasicki cwasicki added this to the v1.0.0-rc milestone Sep 4, 2023
@cwasicki cwasicki self-assigned this Sep 4, 2023
@cwasicki cwasicki force-pushed the rbuffer-copy branch 2 times, most recently from 00e0e7e to 0bc072f Compare September 8, 2023 16:27
@cwasicki
Copy link
Collaborator Author

cwasicki commented Sep 8, 2023

Rebased @matthias-wende-frequenz

@cwasicki cwasicki force-pushed the rbuffer-copy branch 2 times, most recently from 8e26c95 to 48ccae1 Compare September 11, 2023 20:48
@cwasicki
Copy link
Collaborator Author

@matthias-wende-frequenz Ready for review

Copy link
Contributor

@matthias-wende-frequenz matthias-wende-frequenz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two small comments. Looks good otherwise!
Also needs a rebase.

)

@staticmethod
def _wrapped_buffer_window(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have to be a static method? I'd suggest to make it a class method as long it's not used outside the class context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think so, or what is the advantage of a classmethod? I made it static since it's an isolated algorithmic piece which does not need any internal state of the class. Only the buffer argument would change here.

The main motivation was testing purpose (actually contained multiple bugs before), i.e. separate wrapping algorithm from index logic (which will become more tricky in follow-ups). But it can also easily be stripped out when needed elsewhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One example for outside usage I could imagine is the periodic feature extractor, which I assume is using similar code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. It doesn't depend on the internal state. Let's keep it as is.

return datetime.fromtimestamp(i, tz=timezone.utc)


async def test_access_window_by_index() -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if that's the correct function to add the tests. This was supposed to access the window by integer index, but the tests are accessing by datetime object.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added datetime slice tests were added in test_access_window_by_ts_slice. Then a single failure test to for int slices in test_access_window_by_int_slice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I missed that. All good then ;).

Test for expected copy behavior on missing values does not work as
documented.

Signed-off-by: cwasicki <[email protected]>
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]>
This just moves the logic into a separate function to allow better testing
of the logic. Bug found in the logic will be fixed in later commit.

Signed-off-by: cwasicki <[email protected]>
This reworks the method for extracting wrapped buffer to fix a bug
in the existing copy behavior for a specific case.

Signed-off-by: cwasicki <[email protected]>
Changing the default is motivated by favouring data integrity over
performance concerns which are minor in the majority of the expected
applications.

Also make force_copy a keyword argument.

Signed-off-by: cwasicki <[email protected]>
Restore the typical list-like behavior for equal start and end. Would be
inconsistent with the forbidden case start > end.

Signed-off-by: cwasicki <[email protected]>
Expose window functionality of underlying buffer. Only datetime indices
are supported so far.

Signed-off-by: cwasicki <[email protected]>
Signed-off-by: cwasicki <[email protected]>
@matthias-wende-frequenz matthias-wende-frequenz added this pull request to the merge queue Sep 13, 2023
Merged via the queue into frequenz-floss:v0.x.x with commit bf1b22c Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:data-pipeline Affects the data pipeline part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

Development

Successfully merging this pull request may close these issues.

2 participants