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 suggestions deserialization #95

Merged
merged 2 commits into from
May 22, 2024
Merged

Conversation

talmo
Copy link
Contributor

@talmo talmo commented May 22, 2024

This fixes an issue where we fail to load SLP files if they don't contain suggestions data. This was the case for SLP files produced with sleap-io<0.1.1.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling when reading suggestions from datasets. Now returns an empty list if the dataset is not found, enhancing stability and user experience.
  • Chores

    • Updated package version from "0.1.1" to "0.1.2".
  • Tests

    • Added new tests to ensure the correct functionality of reading and writing suggestions.

Copy link
Contributor

coderabbitai bot commented May 22, 2024

Walkthrough

The recent updates introduce exception handling for reading suggestions in the read_suggestions function of sleap_io/io/slp.py, ensuring robustness by returning an empty list if a dataset is missing. Additionally, the package version has been incremented to 0.1.2 in sleap_io/version.py, and new tests have been added in tests/io/test_slp.py to verify the suggestions functionality.

Changes

Files Change Summary
sleap_io/io/slp.py Added exception handling for KeyError in read_suggestions function, returning an empty list if dataset is not found.
sleap_io/version.py Updated version from 0.1.1 to 0.1.2.
tests/io/test_slp.py Added SuggestionFrame import, and new test functions test_suggestions and test_slp_imgvideo.

In code's vast realm where exceptions might roam,
A safeguard now stands, ensuring safe home.
With tests to confirm, and versions anew,
Our code is robust, and bugs are but few.
🐇✨


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration 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

Outside diff range and nitpick comments (2)
tests/io/test_slp.py (2)

Line range hint 57-57: Replace type comparison with isinstance().

-    assert type(labels) == Labels
+    assert isinstance(labels, Labels)

Line range hint 188-188: Replace type comparison with isinstance().

-    assert type(labels.video.backend) == ImageVideo
+    assert isinstance(labels.video.backend, ImageVideo)
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 45941db and 2449901.
Files selected for processing (3)
  • sleap_io/io/slp.py (1 hunks)
  • sleap_io/version.py (1 hunks)
  • tests/io/test_slp.py (3 hunks)
Files skipped from review due to trivial changes (1)
  • sleap_io/version.py
Additional Context Used
Ruff (13)
sleap_io/io/slp.py (3)

27-27: sleap_io.io.utils.write_hdf5_dataset imported but unused


28-28: sleap_io.io.utils.write_hdf5_group imported but unused


29-29: sleap_io.io.utils.write_hdf5_attrs imported but unused

tests/io/test_slp.py (10)

6-6: sleap_io.Edge imported but unused


9-9: sleap_io.LabeledFrame imported but unused


10-10: sleap_io.Track imported but unused


11-11: sleap_io.Point imported but unused


12-12: sleap_io.PredictedPoint imported but unused


25-25: sleap_io.io.slp.serialize_skeletons imported but unused


29-29: Redefinition of unused read_instances from line 22


29-29: sleap_io.io.slp.read_instances imported but unused


57-57: Do not compare types, use isinstance()


188-188: Do not compare types, use isinstance()

Additional comments not posted (3)
tests/io/test_slp.py (2)

33-34: Ensure that the newly added functions read_suggestions and write_suggestions are utilized appropriately in the tests.


245-259: The new test function test_suggestions effectively tests the functionality of reading and writing suggestions, including handling missing datasets. This is a crucial part of the PR's objective to handle files without suggestions data.

sleap_io/io/slp.py (1)

200-204: The addition of exception handling for KeyError in read_suggestions is a critical improvement. It ensures that the function returns an empty list if the suggestions dataset is not found, which aligns with the PR's objective to handle older SLP files without suggestions data.

@@ -12,6 +12,7 @@
PredictedPoint,
PredictedInstance,
Labels,
SuggestionFrame,
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unused import SuggestionFrame.

-    SuggestionFrame,

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
SuggestionFrame,

@talmo talmo merged commit 4af9f38 into main May 22, 2024
6 checks passed
@talmo talmo deleted the talmo/fix-suggestions-deserialization branch May 22, 2024 15:58
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.

1 participant