Skip to content
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

First commit for event index #67

Closed
wants to merge 8 commits into from
Closed

First commit for event index #67

wants to merge 8 commits into from

Conversation

justin13601
Copy link
Owner

@justin13601 justin13601 commented Jun 25, 2024

For #37

Summary by CodeRabbit

  • New Features

    • Introduced event indexing with a new _EVENT_INDEX column in various aggregation and predicate functions.
    • Enhanced extraction and processing of subtree data with event indexing.
  • Improvements

    • Enhanced data consistency by including event index columns in summary outputs.
  • Tests

    • Updated end-to-end tests to include new _LAST_EVENT_INDEX fields.

@justin13601 justin13601 added Enhancement New feature or request priority:critical Things that are critical bug fixes, to be addressed immediately and pushed with minor version update labels Jun 25, 2024
@justin13601 justin13601 self-assigned this Jun 25, 2024
Copy link
Contributor

coderabbitai bot commented Jun 25, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Recent updates across multiple files primarily focus on integrating an _EVENT_INDEX column for enhanced event indexing throughout various functions. These changes include adjustments in import statements, data processing logic, and output summaries to accommodate this new column. This integration enables sophisticated event tracking and processing capabilities in the aggregate.py, extract_subtree.py, predicates.py, and types.py files while ensuring that tests are updated accordingly.

Changes

Files/Groups Change Summary
src/aces/aggregate.py, src/aces/extract_subtree.py, src/aces/predicates.py, src/aces/types.py Added _EVENT_INDEX handling in various functions, including import adjustments and data processing logic to enhance event tracking. Defined new constants in types.py.
tests/test_e2e.py Updated test cases to include _LAST_EVENT_INDEX fields with specific values.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AggregateFunction as aggregate.py
    participant ExtractSubtreeFunction as extract_subtree.py
    participant PredicateFunction as predicates.py

    User->>AggregateFunction: Call aggregate_temporal_window(data)
    AggregateFunction->>AggregateFunction: Process data, use and drop _EVENT_INDEX
    User->>ExtractSubtreeFunction: Call extract_subtree(data)
    ExtractSubtreeFunction->>ExtractSubtreeFunction: Process data with _EVENT_INDEX
    User->>PredicateFunction: Call get_predicates_df()
    PredicateFunction->>PredicateFunction: Create and return dataframe with _EVENT_INDEX
Loading

Poem

In the land of data bright,
_EVENT_INDEX takes its flight,
Through code it weaves, a path so clear,
Enhancing logic, far and near.
With columns added, tests anew,
A stronger structure now in view.
🚀✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e068b97 and 2a8a66b.

Files selected for processing (5)
  • src/aces/aggregate.py (27 hunks)
  • src/aces/extract_subtree.py (5 hunks)
  • src/aces/predicates.py (4 hunks)
  • src/aces/types.py (1 hunks)
  • tests/test_e2e.py (8 hunks)
Additional context used
Ruff
tests/test_e2e.py

7-7: Module level import not at top of file (E402)


8-8: Module level import not at top of file (E402)


9-9: Module level import not at top of file (E402)


11-11: Module level import not at top of file (E402)


12-12: Module level import not at top of file (E402)


13-13: Module level import not at top of file (E402)

src/aces/types.py

305-308: Use ternary operator end_event = self.end_event[1:] if mode == "bound_to_row" else self.end_event instead of if-else-block (SIM108)

Replace if-else-block with end_event = self.end_event[1:] if mode == "bound_to_row" else self.end_event

src/aces/aggregate.py

874-877: Use ternary operator right_inclusive = False if closed in ("left", "both") else True instead of if-else-block (SIM108)

Replace if-else-block with right_inclusive = False if closed in ("left", "both") else True


880-883: Use ternary operator right_inclusive = True if closed in ("right", "both") else False instead of if-else-block (SIM108)

Replace if-else-block with right_inclusive = True if closed in ("right", "both") else False


888-891: Use ternary operator left_inclusive = True if closed in ("left", "both") else False instead of if-else-block (SIM108)

Replace if-else-block with left_inclusive = True if closed in ("left", "both") else False


894-897: Use ternary operator left_inclusive = False if closed in ("right", "both") else True instead of if-else-block (SIM108)

Replace if-else-block with left_inclusive = False if closed in ("right", "both") else True


917-924: Combine if branches using logical or operator (SIM114)

Combine if branches


1013-1021: Combine if branches using logical or operator (SIM114)

Combine if branches

Additional comments not posted (9)
tests/test_e2e.py (1)

132-132: Ensure consistency of _LAST_EVENT_INDEX in test data.

The modifications to the test data to include _LAST_EVENT_INDEX fields are consistent with the changes described in the AI-generated summary. This ensures that the new event indexing logic is covered by the tests.

Also applies to: 143-143, 156-156, 167-167, 180-180, 191-191, 204-204, 215-215

src/aces/types.py (1)

16-16: Review of new types and constants for event indexing.

The introduction of EVENT_INDEX_TYPE, EVENT_INDEX_COLUMN, and LAST_EVENT_INDEX_COLUMN is consistent with the changes described in the AI-generated summary. These additions are crucial for supporting the new event indexing features across the application.
[APROVED]

Also applies to: 26-27

src/aces/extract_subtree.py (1)

11-11: Review of modifications to extract_subtree function.

The updates to the extract_subtree function to include handling of the _EVENT_INDEX column are consistent with the changes described in the AI-generated summary. These modifications are crucial for ensuring that the function correctly processes and includes this column in the input data, which is essential for the new event indexing functionality.

Also applies to: 137-137, 149-160, 248-333

src/aces/predicates.py (2)

13-14: Updated import statements to include event indexing types.

The inclusion of EVENT_INDEX_COLUMN and EVENT_INDEX_TYPE aligns with the changes outlined in the summary, ensuring the necessary types are available for handling the new _EVENT_INDEX column. This is crucial for maintaining consistency across modules that will interact with event indexes.


Line range hint 490-520: Introduction of _EVENT_INDEX in DataFrame output.

The addition of _EVENT_INDEX in the DataFrame output of get_predicates_df function is executed correctly. The column is computed and added in lines 642-645, ensuring every event has a unique index within its subject group. This is crucial for tracking events in sequence analysis or temporal comparisons.

However, ensure that all downstream processes that consume this DataFrame are aware of and correctly handle the new _EVENT_INDEX column.

src/aces/aggregate.py (4)

7-12: Review of imports and constants:

The import of EVENT_INDEX_COLUMN aligns with the PR's objective to handle an event index column. This addition appears necessary and correct for the functions modified in this file.


87-87: Ensure correct handling of _EVENT_INDEX column:

The repeated use of .drop("_EVENT_INDEX") in different configurations of the aggregate_temporal_window function is consistent with the need to remove this column post-aggregation. This change is in line with the PR's objectives and seems correctly implemented across different scenarios.

Also applies to: 102-102, 117-117, 132-132, 147-147, 162-162, 181-181, 196-196


314-314: Review of _EVENT_INDEX handling in aggregate_event_bound_window:

The introduction and subsequent dropping of _EVENT_index within aggregate_event_bound_window function is consistent with the handling in other functions. This ensures that the event index does not propagate beyond its necessary scope within the data pipeline.

Also applies to: 319-319, 336-336, 337-337, 353-353, 354-354, 370-370, 371-371


Line range hint 214-237: Complex handling of conditions and _EVENT_INDEX in boolean_expr_bound_sum:

The function boolean_expr_bound_sum has been modified to incorporate the _EVENT_index in its operations, reflecting the broader PR objectives. The handling of this column and the complex conditional logic used for boundary calculations appear correctly implemented, maintaining the integrity of the data transformation logic.

Also applies to: 512-512, 693-693, 715-715, 737-737, 759-759, 781-781, 803-803, 825-825, 847-847

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (1)
src/aces/extract_subtree.py (1)

147-149: Update the example output shape.

The shape of the example output DataFrame has changed from (5, 2) to (5, 3) due to the inclusion of the _EVENT_INDEX column. Ensure that all example outputs are updated to reflect this change.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2a8a66b and c36b5bd.

Files selected for processing (3)
  • src/aces/main.py (1 hunks)
  • src/aces/extract_subtree.py (5 hunks)
  • src/aces/predicates.py (5 hunks)
Additional comments not posted (7)
src/aces/__main__.py (1)

49-49: Verify the DataFrame renaming method.

The change in the rename method from using the columns keyword to directly passing a dictionary could potentially cause issues if the DataFrame does not handle this method signature as expected. Ensure that the DataFrame correctly interprets this method signature.

src/aces/extract_subtree.py (4)

11-11: Ensure consistency in column handling.

The addition of the EVENT_INDEX_COLUMN import indicates that the _EVENT_INDEX column is now being handled. Ensure that this column is consistently handled throughout the function.


137-137: Verify the inclusion of _EVENT_INDEX in the DataFrame.

The addition of the _EVENT_INDEX column in the example DataFrame indicates that this column is now part of the data processing. Ensure that this column is correctly handled in all relevant DataFrame operations.


248-250: Exclude _EVENT_INDEX from predicate_cols.

The exclusion of the _EVENT_INDEX column from predicate_cols is necessary to ensure that this column is not treated as a predicate. This change is correct and should be maintained.


333-333: Include _EVENT_INDEX in the summary.

The inclusion of the _EVENT_INDEX column in the summary DataFrame ensures that this column is part of the output. This change is correct and should be maintained.

src/aces/predicates.py (2)

13-14: Ensure consistency in column handling.

The addition of the EVENT_INDEX_COLUMN and EVENT_INDEX_TYPE imports indicates that the _EVENT_INDEX column is now being handled. Ensure that these constants are consistently used throughout the function.


490-500: Verify the inclusion of _EVENT_INDEX in the DataFrame.

The addition of the _EVENT_INDEX column in the example DataFrame indicates that this column is now part of the data processing. Ensure that this column is correctly handled in all relevant DataFrame operations.

src/aces/predicates.py Outdated Show resolved Hide resolved
@justin13601 justin13601 added the Impacts Benchmark Impacts the 2024 Summer / Fall Distributed MEDS Benchmarking Effort label Jul 28, 2024
@justin13601 justin13601 marked this pull request as draft July 29, 2024 08:41
src/aces/types.py Outdated Show resolved Hide resolved
src/aces/predicates.py Show resolved Hide resolved
src/aces/extract_subtree.py Outdated Show resolved Hide resolved
src/aces/aggregate.py Show resolved Hide resolved
... })
>>> aggregate_event_bound_window(df, ToEventWindowBounds(True, "is_C", True, None))
>>> aggregate_event_bound_window(df, ToEventWindowBounds(True, "is_C", True, None)).drop("timestamp")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would keep the "timestamp" column in these tests, and just set the pl.Config params to print wider dataframes.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Actually I did this more to satistfy the pre-commit rules of lines not extending past 120 characters - should doctests still follow these rules? What's the best way to go around this?

src/aces/aggregate.py Show resolved Hide resolved
@mmcdermott
Copy link
Collaborator

I think more generally here, each aggregate function should return:

  1. The timestamp at the start of the window. If the window does not exist, this should be null.
  2. The timestamp at the end of the window. If the window does not exist, this should be null.
  3. The index of the first event inside the window. If there are no events in the window, this should be null.
  4. The index of the last event inside the window. If there are no events in the window, this should be null.

Note that the distinction between "the window existing" and "events existing" is as follows:

  1. A window is an interval in the patient timeline where (a) the left endpoint is <= the right endpoint and (b) either left or right endpoint can be open or closed. A window does not exist if either of these constraints are not satisfied. We can also modify this to say that "windows don't exist if they are provably empty -- e.g., [12:01, 12:01) of (3:23, 3:23)" or that "windows with equal left and right endpoints where both are open don't exist" as desired.
  2. Events are in the window if they occur with a timestamp within the interval defined by the window (respecting the openness or closedness of its bounds).

@mmcdermott
Copy link
Collaborator

@justin13601, as we'll discuss more shortly, I'd actually suggest de-prioritizing this in favor of other things, and closing the PR for now as a result (with plans to re-visit later). Does that sound reasonable to you? If not, feel free to re-open.

@mmcdermott mmcdermott closed this Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Impacts Benchmark Impacts the 2024 Summer / Fall Distributed MEDS Benchmarking Effort priority:critical Things that are critical bug fixes, to be addressed immediately and pushed with minor version update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants