Add metadata support to SuggestionFrame for preserving group information#251
Merged
Conversation
This commit adds a metadata dictionary to SuggestionFrame (similar to Video.backend_metadata) to store arbitrary metadata that isn't explicitly represented in the data model. The primary use case is preserving the "group" key when reading/writing SLP files, which was previously being discarded. Changes: - Add metadata attribute to SuggestionFrame class with factory default - Update read_suggestions to extract and pass group metadata - Update write_suggestions to write group metadata if available - Add comprehensive tests for metadata round-trip and backward compatibility This maintains backward compatibility while enabling metadata preservation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #251 +/- ##
==========================================
+ Coverage 93.82% 93.89% +0.07%
==========================================
Files 28 28
Lines 5763 5765 +2
Branches 1528 1528
==========================================
+ Hits 5407 5413 +6
+ Misses 136 134 -2
+ Partials 220 218 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Remove unused variable and apply formatting changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Use .get() with default value instead of conditional check since group key should always be present. This simplifies the code and improves coverage. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a
metadatadictionary toSuggestionFrame(similar toVideo.backend_metadata) to store arbitrary metadata that isn't explicitly represented in the data model. The primary use case is preserving thegroupkey when reading/writing SLP files, which was previously being discarded.Key Changes
1. Added
metadataattribute toSuggestionFrame(sleap_io/model/suggestions.py)metadata: dict[str, any]attribute with factory default (empty dict)Video.backend_metadatafor consistency2. Updated
read_suggestions(sleap_io/io/slp.py)groupkey from JSON data if presentSuggestionFramevia the newmetadataparameter3. Updated
write_suggestions(sleap_io/io/slp.py)suggestion.metadatacontains a"group"key0for backward compatibility4. Added comprehensive tests (tests/io/test_slp.py)
groupmetadata with different values (0, 1, 2)Example Usage
Testing
All tests pass:
test_suggestions_metadatavalidates round-trip preservationtest_suggestionsvalidates backward compatibilitytests/io/test_slp.pypassBackward Compatibility
This change is fully backward compatible:
groupmetadata will default togroup=0Benefits
groupmetadata that was previously being lostVideo.backend_metadata)🤖 Generated with Claude Code