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 Looker Classifications handing #5322

Merged
merged 9 commits into from
Jan 3, 2025

Conversation

benjaminpkane
Copy link
Contributor

@benjaminpkane benjaminpkane commented Dec 27, 2024

What changes are proposed in this pull request?

The ClassificationsOverlay does not have a label attribute. Resolves #5317

How is this patch tested? If it is not, please explain why.

Unit test for edge cases

Release Notes

  • Fixed visualizer rendering for classification labels

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Introduced a new function for retrieving array buffers from overlays.
    • Added new overlay types: Detection, Heatmap, and Segmentation.
  • Bug Fixes

    • Improved logic for handling overlay data to enhance performance and reliability.
    • Updated cleanup method to prevent potential errors.
  • Chores

    • Adjusted imports for better modularity and organization.
    • Enhanced type safety in utility functions for improved reliability.
    • Added new test suite for the viewsAreEqual function to ensure correct behavior.

@benjaminpkane benjaminpkane added bug Bug fixes app Issues related to App features labels Dec 27, 2024
@benjaminpkane benjaminpkane self-assigned this Dec 27, 2024
Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Walkthrough

The pull request modifies the abstract.ts file in the Looker package, focusing on improving overlay handling and data processing. The changes introduce a new function for retrieving array buffers and update the updateSample method to handle overlay data more robustly. Modifications include type-checking for overlays, adjusting buffer management, and implementing safer method invocation through optional chaining. Additionally, type annotations are added to utility functions in utils.ts, enhancing type safety and error handling.

Changes

File Change Summary
app/packages/looker/src/lookers/abstract.ts - Updated updateSample method to use retrieveArrayBuffers for buffer retrieval
- Improved overlay cleanup using optional chaining
- Removed unused import for LabelMask
app/packages/state/src/utils.ts - Added type annotations to filterView and viewsAreEqual functions
- Corrected sorting logic in stringifyObj function
app/packages/state/src/utils.test.ts - Added new test suite for viewsAreEqual function with five test cases
app/packages/looker/src/lookers/utils.ts - Added retrieveArrayBuffers function for handling overlay buffers
- Added imports for overlay classes
app/packages/looker/src/lookers/utils.test.ts - Added test for retrieveArrayBuffers function

Assessment against linked issues

Objective Addressed Explanation
Prevent web app crash when clicking label tags [#5317]
Resolve TypeError related to 'mask' undefined

Possibly related PRs

  • Fix updateSample in useLooker #4905: This PR modifies the updateSample method in the useLooker hook, which is directly related to the changes made in the updateSample method of the AbstractLooker class in the main PR.
  • sample update / overlay recoloring performance optimization #5247: This PR also modifies the updateSample method in the AbstractLooker class, enhancing memory management and performance during sample updates, which aligns with the changes in the main PR.
  • improve overlay rendering performance #5156: This PR focuses on improving overlay rendering performance, which is relevant to the changes in the main PR that involve handling overlays and memory management in the AbstractLooker class.
  • Fix #5199 #5264: This PR introduces a new utility function hasFrame that is used in the VideoLooker class, which is relevant to the overall functionality of lookers and may relate to the changes in the main PR regarding overlays and sample updates.

Suggested reviewers

  • sashankaryal
  • imanjra

Poem

🐰 In the realm of code, where overlays dance,
A rabbit hops through types with a glance,
Buffers checked, methods chained with care,
No more crashes to give us a scare!
Debugging magic, smooth and light,
Our digital world now shines so bright! 🌟


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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: 0

🧹 Nitpick comments (3)
app/packages/looker/src/lookers/abstract.ts (3)

27-29: Add a short docstring for new overlay imports
While these imports look good, consider adding a short docstring or code comment clarifying the purpose of each overlay to improve clarity in the codebase.


556-557: Leverage the existing buffer checks
There is a blank line before pushing buffer to arrayBuffers. This is more of a style preference than a functional concern, but be mindful of extra lines that could reduce visual clarity.


752-752: Ensure robust cleanup error handling
The optional chaining on overlay.cleanup?.() is a good safeguard. However, if a cleanup error arises, ensure it is handled or logged to prevent silent failures and aid debugging.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18dde78 and dad866d.

📒 Files selected for processing (1)
  • app/packages/looker/src/lookers/abstract.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/looker/src/lookers/abstract.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (1)
app/packages/looker/src/lookers/abstract.ts (1)

534-540: Check for missing or undefined overlay.label
Before accessing overlay.label.mask or overlay.label.map, ensure overlay.label is defined. Otherwise, if overlay.label is unexpectedly null, a runtime error may occur.

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: 0

🧹 Nitpick comments (1)
app/packages/state/src/utils.ts (1)

68-79: Check behavior for string inputs in viewsAreEqual.

When viewOne and viewTwo are both strings with identical content, the initial strict equality check (===) correctly treats them as equal. However, other string nuances (e.g., leading/trailing spaces) might lead to unexpected comparisons. If partial matches or case-insensitive comparisons are desired, consider customizing the comparison logic.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dad866d and cc499d5.

⛔ Files ignored due to path filters (1)
  • app/packages/looker/tsconfig.json is excluded by !**/*.json
📒 Files selected for processing (1)
  • app/packages/state/src/utils.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/state/src/utils.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (1)
app/packages/state/src/utils.ts (1)

60-60: Type annotation improvement is good to see.

By explicitly typing the parameter as State.Stage[], this prevents inadvertent misuse of the filterView function. It also ensures better clarity for future readers and contributors.

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: 0

🧹 Nitpick comments (1)
app/packages/state/src/utils.test.ts (1)

12-20: Expand test coverage for array-based views

Currently, there is only a test for empty arrays. Consider adding more scenarios, such as different array lengths, partially similar arrays, or objects within arrays, to ensure viewsAreEqual is thoroughly validated.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cc499d5 and 2744d55.

📒 Files selected for processing (1)
  • app/packages/state/src/utils.test.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/state/src/utils.test.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (1)
app/packages/state/src/utils.test.ts (1)

2-2: Ensure comprehensive testing of all newly imported functions

While adding viewsAreEqual to the import statement is correct, confirm that all required functionality is covered by unit tests. This prevents future regressions if the function is referenced in other test suites.

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: 0

🧹 Nitpick comments (2)
app/packages/looker/src/lookers/utils.test.ts (1)

2-7: Consider adding test coverage for list overlays with actual data.

Currently, these imported overlay classes are tested only with empty or minimal data. It could be beneficial to introduce test scenarios in which overlays contain real data that produce non-empty array buffers, ensuring more comprehensive coverage of retrieveArrayBuffers under varying conditions.

app/packages/looker/src/lookers/utils.ts (1)

13-57: Solid approach for handling detached ArrayBuffers and fallback logic.

The retrieval logic, along with the early return for detached buffers, is well structured. One minor improvement could be introducing optional chaining for accessing label data, e.g. overlay.label?.mask, as a defensive measure in case of overlays with unexpected label structures.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2744d55 and 2b72978.

📒 Files selected for processing (3)
  • app/packages/looker/src/lookers/abstract.ts (4 hunks)
  • app/packages/looker/src/lookers/utils.test.ts (2 hunks)
  • app/packages/looker/src/lookers/utils.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
app/packages/looker/src/lookers/utils.test.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/lookers/abstract.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/lookers/utils.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (3)
app/packages/looker/src/lookers/utils.test.ts (1)

26-62: All tests currently return an empty array.

While these tests confirm the absence of buffers, it might be worth verifying at least one scenario where real buffers exist. This would ensure that retrieveArrayBuffers is fully validated for overlays that hold actual mask/map data.

app/packages/looker/src/lookers/abstract.ts (2)

525-525: Verify overlay availability before transferring.

When calling retrieveArrayBuffers(this.sampleOverlays), ensure your sample overlays are fully loaded to avoid passing undefined or incomplete data to loadSample. If there's any asynchronous loading involved, it would be prudent to make certain that this.sampleOverlays is populated before transfer.


710-710: Good approach for cleaning up overlays conditionally.

Calling overlay.cleanup?.() accommodates overlays that lack a cleanup method. This helps prevent errors. No further issues found here.

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

🧹 Nitpick comments (1)
app/packages/looker/src/lookers/utils.test.ts (1)

38-54: Improve test data quality

Consider using more realistic test data instead of empty objects and arrays. This would help ensure the functionality works with actual use cases. For example:

  • Add meaningful tags
  • Include actual point coordinates for PolylineOverlay
  • Use realistic IDs
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b72978 and 0076aa6.

📒 Files selected for processing (1)
  • app/packages/looker/src/lookers/utils.test.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/looker/src/lookers/utils.test.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (1)
app/packages/looker/src/lookers/utils.test.ts (1)

2-8: Verify the import location of TemporalDetectionOverlay

The TemporalDetectionOverlay is imported from "../overlays/classifications", but its name suggests it should be in a detection-related file. Consider verifying if this is the intended location.

✅ Verification successful

The import location of TemporalDetectionOverlay is correct

The TemporalDetectionOverlay is correctly imported from "../overlays/classifications" as it extends ClassificationsOverlay and is specifically designed to handle temporal classification data with support intervals. The implementation shows it's a specialized version of ClassificationsOverlay that filters labels based on temporal properties and frame numbers, which aligns with its placement in the classifications module.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the actual implementation location and any other potential references
rg --type ts "class TemporalDetectionOverlay" app/packages/looker/src/

Length of output: 194


Script:

#!/bin/bash
# Let's check the implementation details of TemporalDetectionOverlay to understand its relationship with ClassificationsOverlay
ast-grep --pattern 'class TemporalDetectionOverlay extends ClassificationsOverlay<$$$>'

Length of output: 89


Script:

#!/bin/bash
# Let's examine the content of the classifications.ts file to understand the relationship
cat app/packages/looker/src/overlays/classifications.ts

Length of output: 9639

app/packages/looker/src/lookers/utils.test.ts Show resolved Hide resolved
Copy link
Contributor

@sashankaryal sashankaryal left a comment

Choose a reason for hiding this comment

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

lgtm! thanks for the new tests

@benjaminpkane benjaminpkane merged commit 199872a into develop Jan 3, 2025
12 checks passed
@benjaminpkane benjaminpkane deleted the bugfix/looker-classifications branch January 3, 2025 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Issues related to App features bug Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

On the Demo Site, clicking label tags in the BDD example crashes the web app
2 participants