-
Notifications
You must be signed in to change notification settings - Fork 11
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
Labels QOL enhancements #81
Conversation
WalkthroughThe recent updates bring significant enhancements to data management in the Changes
Poem
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Additional comments not posted (1)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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
elif type(key) == slice: | ||
return [self.labeled_frames[i] for i in range(*key.indices(len(self)))] | ||
elif type(key) == list: | ||
return [self.labeled_frames[i] for i in key] | ||
elif isinstance(key, np.ndarray): | ||
return [self.labeled_frames[i] for i in key.tolist()] | ||
elif type(key) == tuple and len(key) == 2: | ||
video, frame_idx = key | ||
res = self.find(video, frame_idx) | ||
if len(res) == 1: | ||
return res[0] | ||
elif len(res) == 0: | ||
raise IndexError( | ||
f"No labeled frames found for video {video} and " | ||
f"frame index {frame_idx}." | ||
) | ||
elif type(key) == Video: | ||
res = self.find(key) | ||
if len(res) == 0: | ||
raise IndexError(f"No labeled frames found for video {key}.") | ||
return res |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using isinstance()
for type checking instead of direct type comparison. This is more Pythonic and supports inheritance.
- elif type(key) == slice:
+ elif isinstance(key, slice):
- elif type(key) == list:
+ elif isinstance(key, list):
- elif type(key) == tuple and len(key) == 2:
+ elif isinstance(key, tuple) and len(key) == 2:
- elif type(key) == Video:
+ elif isinstance(key, Video):
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.
elif type(key) == slice: | |
return [self.labeled_frames[i] for i in range(*key.indices(len(self)))] | |
elif type(key) == list: | |
return [self.labeled_frames[i] for i in key] | |
elif isinstance(key, np.ndarray): | |
return [self.labeled_frames[i] for i in key.tolist()] | |
elif type(key) == tuple and len(key) == 2: | |
video, frame_idx = key | |
res = self.find(video, frame_idx) | |
if len(res) == 1: | |
return res[0] | |
elif len(res) == 0: | |
raise IndexError( | |
f"No labeled frames found for video {video} and " | |
f"frame index {frame_idx}." | |
) | |
elif type(key) == Video: | |
res = self.find(key) | |
if len(res) == 0: | |
raise IndexError(f"No labeled frames found for video {key}.") | |
return res | |
elif isinstance(key, slice): | |
return [self.labeled_frames[i] for i in range(*key.indices(len(self)))] | |
elif isinstance(key, list): | |
return [self.labeled_frames[i] for i in key] | |
elif isinstance(key, np.ndarray): | |
return [self.labeled_frames[i] for i in key.tolist()] | |
elif isinstance(key, tuple) and len(key) == 2: | |
video, frame_idx = key | |
res = self.find(video, frame_idx) | |
if len(res) == 1: | |
return res[0] | |
elif len(res) == 0: | |
raise IndexError( | |
f"No labeled frames found for video {video} and " | |
f"frame index {frame_idx}." | |
) | |
elif isinstance(key, Video): | |
res = self.find(key) | |
if len(res) == 0: | |
raise IndexError(f"No labeled frames found for video {key}.") | |
return res |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #81 +/- ##
==========================================
+ Coverage 95.16% 95.33% +0.17%
==========================================
Files 13 13
Lines 1551 1609 +58
==========================================
+ Hits 1476 1534 +58
Misses 75 75 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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
save_jabs, | ||
load_video, | ||
load_file, | ||
save_file, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [7-28]
Consider addressing the unused imports.
Many imports in this file are flagged as unused. If these are meant to be available for external use, add them to the __all__
list to explicitly export them. Otherwise, consider removing them to clean up the codebase. Here's an example of how you might modify the code:
- from sleap_io.model.skeleton import Node, Edge, Skeleton, Symmetry
- from sleap_io.model.video import Video
- from sleap_io.model.instance import (
- Point,
- PredictedPoint,
- Track,
- Instance,
- PredictedInstance,
- )
- from sleap_io.model.labeled_frame import LabeledFrame
- from sleap_io.model.labels import Labels
- from sleap_io.io.main import (
- load_slp,
- save_slp,
- load_nwb,
- save_nwb,
- load_labelstudio,
- save_labelstudio,
- load_jabs,
- save_jabs,
- load_video,
- load_file,
- save_file,
- )
+ __all__ = ['Node', 'Edge', 'Skeleton', 'Symmetry', 'Video', 'Point', 'PredictedPoint', 'Track', 'Instance', 'PredictedInstance', 'LabeledFrame', 'Labels', 'load_slp', 'save_slp', 'load_nwb', 'save_nwb', 'load_labelstudio', 'save_labelstudio', 'load_jabs', 'save_jabs', 'load_video', 'load_file', 'save_file']
LabeledFrame.remove_predictions
: Remove predicted instances from a labeled frame.LabeledFrame.remove_empty_instances
: Remove instances with no visible points from a labeled frame.Labels.save
: Instance-level convenience wrapper forsio.save_file
.Labels.clean
: Remove unused or empty frames, instances, videos, skeletons and tracks.Labels.remove_predictions
: Remove predicted instances from all labeled frames (Remove predictions from labels #69).Labels.__getitem__
: Now supports lists, slices, numpy arrays, tuples of(Video, frame_idx)
andVideo
.Summary by CodeRabbit
LabeledFrame
class with methods to remove specific predictions and empty instances.LabeledFrame
.