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

Update labels videos list on replace #128

Merged
merged 1 commit into from
Oct 4, 2024
Merged

Conversation

talmo
Copy link
Contributor

@talmo talmo commented Oct 4, 2024

Fix: Labels.replace_videos now correctly updates the Labels.videos list in addition to frame and suggestion references.

Summary by CodeRabbit

  • New Features

    • Enhanced video and filename replacement methods for improved flexibility and error handling in the Labels class.
    • Introduced new test cases to validate the functionality of the Labels class, including splitting and training data creation.
  • Bug Fixes

    • Improved error handling for edge cases in video and filename replacement methods.
  • Tests

    • Expanded and refined test cases for existing methods to ensure robustness and correct behavior under various conditions.

Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The pull request introduces modifications to the Labels class in the sleap_io/model/labels.py file, enhancing the replace_videos and replace_filenames methods. The replace_videos method now includes a conditional to assign old_videos based on new_videos, ensuring proper replacements. The replace_filenames method implements checks for input consistency and raises errors for mismatched inputs. Additionally, the test suite for the Labels class is updated with new test cases and enhanced assertions to ensure the robustness of these methods under various scenarios.

Changes

File Change Summary
sleap_io/model/labels.py - Updated replace_videos method to include conditional logic for old_videos and ensure self.videos is updated after processing.
- Enhanced replace_filenames method to check for valid input combinations and raise ValueError for mismatched inputs.
tests/model/test_labels.py - Updated test_replace_videos and test_replace_filenames methods with expanded assertions and error handling.
- Added test_split and test_make_training_splits methods to validate new functionalities.

Possibly related PRs

🐰 In the meadow, videos play,
With filenames swapped in a clever way.
A hop, a skip, the tests now run,
Ensuring our changes shine like the sun.
Robust and ready, the labels we keep,
In the world of data, our bunnies leap! 🌼


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

🧹 Outside diff range and nitpick comments (1)
sleap_io/model/labels.py (1)

496-497: Effective update of self.videos list

The new implementation correctly updates the self.videos list using the video_map. This ensures that all video references are properly maintained after the replacement process.

Consider this minor optimization for clarity and potential performance improvement:

- self.videos = [video_map.get(video, video) for video in self.videos]
+ self.videos = list(map(lambda v: video_map.get(v, v), self.videos))

This change uses map and lambda, which can be slightly more efficient for larger lists and may be considered more idiomatic in some Python circles.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ddf5277 and a58fbf0.

📒 Files selected for processing (2)
  • sleap_io/model/labels.py (2 hunks)
  • tests/model/test_labels.py (1 hunks)
🔇 Additional comments (3)
sleap_io/model/labels.py (2)

476-482: Improved flexibility in replace_videos method

This new conditional block enhances the replace_videos method by allowing users to provide only new_videos without specifying old_videos. It automatically assigns self.videos to old_videos when the number of new_videos matches the existing videos. This change improves the method's usability while maintaining data integrity.


Line range hint 476-497: Summary of replace_videos method improvements

The changes to the replace_videos method in the Labels class effectively address the PR objective. The method now correctly updates the Labels.videos list and handles cases where only new_videos are provided. These improvements enhance the flexibility and robustness of the video replacement process.

Key improvements:

  1. Automatic assignment of old_videos when only new_videos are provided.
  2. Proper updating of the self.videos list after processing labeled frames and suggestions.

These changes will likely improve the overall functionality and user experience when working with video replacements in the SLEAP-IO library.

tests/model/test_labels.py (1)

359-363: Test correctly verifies video replacement functionality

The test ensures that after calling labels.replace_videos, all LabeledFrame and SuggestionFrame objects have their video.filename updated to 'fake.mp4', confirming that replace_videos works as intended.


for lf in labels:
assert lf.video.filename == "fake.mp4"

for sf in labels.suggestions:
assert sf.video.filename == "fake.mp4"

assert labels.video.filename == "fake.mp4"
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure single video access is valid after replacement

Accessing labels.video will raise a ValueError if labels.videos contains more than one video. Since replace_videos replaces the videos, consider verifying that only one video is present before asserting labels.video.filename.

Apply this change to confirm only one video exists:

assert len(labels.videos) == 1
assert labels.video.filename == "fake.mp4"

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.38%. Comparing base (ddf5277) to head (a58fbf0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #128   +/-   ##
=======================================
  Coverage   96.38%   96.38%           
=======================================
  Files          15       15           
  Lines        2046     2049    +3     
=======================================
+ Hits         1972     1975    +3     
  Misses         74       74           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@talmo talmo merged commit 2aa891d into main Oct 4, 2024
9 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 4, 2024
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