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

fix minor api load issues #459

Closed
wants to merge 1 commit into from
Closed

fix minor api load issues #459

wants to merge 1 commit into from

Conversation

anayapouget
Copy link

@anayapouget anayapouget commented Jan 27, 2025

Summary by CodeRabbit

  • Bug Fix: Improved the logic for handling out-of-order timestamps and duplicate keys in the data index, enhancing data consistency and reliability.
  • Refactor: Optimized the calculation of initial repeat part column index based on BONSAI_SLEAP version. This dynamic determination of columns to skip enhances performance and maintainability.

Copy link

github-actions bot commented Jan 27, 2025

Image description CodeRabbit

Walkthrough

The overall change focuses on enhancing the logic related to handling out-of-order timestamps and duplicate keys in the data index. The modification also includes a dynamic calculation of the initial repeat part column index based on the version of BONSAI_SLEAP. This adjustment allows for a more flexible and efficient handling of columns, improving the performance and maintainability of the code.

Changes

Files Summary
aeon/io/api.py, aeon/io/reader.py The code modifies the logic for checking out-of-order timestamps and duplicate keys in the data index. It also adjusts the calculation of the initial repeat part column index based on a condition related to the version of BONSAI_SLEAP. The number of columns to skip before calculating the index is now determined dynamically, enhancing flexibility and efficiency.

Uplevel your code reviews with CodeRabbit Pro

CodeRabbit Pro

If you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Image description CodeRabbit

Commits Files that changed from the base of the PR and between 83cd905 and 3a06a7f commits.
Files selected (2)
  • aeon/io/api.py (1)
  • aeon/io/reader.py (1)
Review comments generated (2)
  • Review: 2
  • LGTM: 0

Tips

Chat with Image description CodeRabbit Bot (@coderabbitai)

  • Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
  • Invite the bot into a review comment chain by tagging @coderabbitai in a reply.

Code suggestions

  • The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
  • You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.

Pausing incremental reviews

  • Add @coderabbitai: ignore anywhere in the PR description to pause further reviews from the bot.

Comment on lines +148 to +153
if not data.index.is_monotonic_increasing:
warnings.warn(
f"data index for {reader.pattern} contains out-of-order timestamps!", stacklevel=2
)
data = data.sort_index()
else:
elif data.index.has_duplicates:

Choose a reason for hiding this comment

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

Image description CodeRabbit

The logic in the new hunk seems to be incorrect. The elif statement on line 153 will not execute if the first condition on line 148 is true, even if there are duplicate keys in the data index. This could lead to issues if the data index has both out-of-order timestamps and duplicate keys. I suggest changing the elif to an if so that both conditions can be checked independently.

-            elif data.index.has_duplicates:
+            if data.index.has_duplicates:
                 warnings.warn(f"data index for {reader.pattern} contains duplicate keys!", stacklevel=2)
                 data = data[~data.index.duplicated(keep="first")]

Comment on lines +364 to +366
if repeat_idxs: # drop x, y, and likelihood cols for repeat parts (skip first cols)
num_cols_skip = 5 if bonsai_sleap_v == BONSAI_SLEAP_V2 else 6
init_rep_part_col_idx = (repeat_idxs - 1) * 3 + num_cols_skip

Choose a reason for hiding this comment

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

Image description CodeRabbit

The check for repeat_idxs is not correct. In Python, an empty numpy array evaluates to True in a boolean context, which means the code inside the if block will execute even when repeat_idxs is empty. This could lead to unexpected behavior. You should explicitly check if repeat_idxs is not empty by using len(repeat_idxs) > 0.

-         if repeat_idxs:  
+         if len(repeat_idxs) > 0:  
            num_cols_skip = 5 if bonsai_sleap_v == BONSAI_SLEAP_V2 else 6
            init_rep_part_col_idx = (repeat_idxs - 1) * 3 + num_cols_skip

@glopesdev
Copy link
Contributor

@anayapouget thanks for these. Since they are changes to the low-level load API, do you mind submitting these to SainsburyWellcomeCentre/aeon_api?

We are now tracking the low-level reader API in a separate repository.

@anayapouget anayapouget deleted the ap-api-load-fixes branch January 31, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants