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 #4890 #4891

Merged
merged 1 commit into from
Oct 4, 2024
Merged

Fix #4890 #4891

merged 1 commit into from
Oct 4, 2024

Conversation

benjaminpkane
Copy link
Contributor

@benjaminpkane benjaminpkane commented Oct 4, 2024

What changes are proposed in this pull request?

Resolves #4890

import fiftyone as fo
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset("quickstart-video", max_samples=1)

sample = dataset.first()
sample["classes"] = fo.Classifications(classifications=[fo.Classification(label="class")])
sample["detections"] = fo.TemporalDetections(detections=[fo.TemporalDetection(label="detection")])
sample.save()

session = fo.launch_app(dataset)
Screenshot 2024-10-04 at 10 42 39 AM

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

Unit tests for the Classifications and TemporalDetections special cases

Release Notes

  • Fixed |Classifications| and |TemporalDetections| grid rendering

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

    • Enhanced handling of classifications and temporal detections in bubble processing.
  • Bug Fixes

    • Improved functionality of the getBubbles function to correctly process nested data structures.
  • Tests

    • Expanded test coverage for the getBubbles function with new scenarios for classifications and temporal detections.

@benjaminpkane benjaminpkane added bug Bug fixes app Issues related to App features labels Oct 4, 2024
@benjaminpkane benjaminpkane requested a review from a team October 4, 2024 14:42
@benjaminpkane benjaminpkane self-assigned this Oct 4, 2024
Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The pull request introduces new constants and test cases in the bubbles.test.ts file, enhancing the test suite for the getBubbles function. It adds handling for classifications and temporal detections. In the bubbles.ts file, modifications are made to the getBubbles function to improve how the out.values array is processed, specifically using the unwind function for better handling of nested data structures.

Changes

File Path Change Summary
app/packages/looker/src/elements/common/bubbles.test.ts Added constants CLASSIFICATIONS and TEMPORAL_DETECTIONS, and expanded test cases for getBubbles.
app/packages/looker/src/elements/common/bubbles.ts Modified getBubbles to use the unwind function for processing out.values based on classifications and temporal detections.

Assessment against linked issues

Objective Addressed Explanation
Ensure fo.Classifications labels are displayed (4890)

Possibly related PRs

Suggested reviewers

  • sashankaryal

🐇 In the land where the bubbles play,
New constants join the fray today.
With tests that dance and functions that gleam,
We hop through code, a coder's dream!
Let's celebrate with joy and cheer,
For every change brings us near! 🎉


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.

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 (3)
app/packages/looker/src/elements/common/bubbles.test.ts (2)

200-215: Add assertion to verify the result of getBubbles for classifications.

The new test case for classifications is well-structured and consistent with existing tests. However, it's missing an assertion to verify the result of the getBubbles call. Consider adding an expectation to ensure the function behaves correctly with the classifications input.

Here's a suggested improvement:

expect(
  getBubbles(
    "classes",
    { classes: { classifications: [{ label: "label" }] } },
    { classes: classifications }
  )
).toEqual([classifications, [{ classifications: [{ label: "label" }] }]]);

217-231: Add assertion to verify the result of getBubbles for temporal detections.

The new test case for temporal detections is well-structured and consistent with existing tests. However, like the classifications test, it's missing an assertion to verify the result of the getBubbles call. Consider adding an expectation to ensure the function behaves correctly with the temporal detections input.

Here's a suggested improvement:

expect(
  getBubbles(
    "temporal",
    { temporal: { detections: [{ label: "label" }] } },
    { temporal: temporalDetections }
  )
).toEqual([temporalDetections, [{ detections: [{ label: "label" }] }]]);
app/packages/looker/src/elements/common/bubbles.ts (1)

57-60: Enhance type safety by avoiding unnecessary type assertions

The use of type assertions (as Sample[]) could potentially mask type mismatches and suppress compiler warnings. Consider refining the types returned by the unwind function and the flatMap callbacks to ensure TypeScript can infer the correct types without assertions. This improves type safety and helps catch potential issues at compile time.

Also applies to: 64-67

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2580fb5 and 5b17779.

📒 Files selected for processing (2)
  • app/packages/looker/src/elements/common/bubbles.test.ts (2 hunks)
  • app/packages/looker/src/elements/common/bubbles.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
app/packages/looker/src/elements/common/bubbles.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/elements/common/bubbles.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 (2)
app/packages/looker/src/elements/common/bubbles.test.ts (2)

3-8: LGTM: New imports added correctly.

The new constants CLASSIFICATIONS and TEMPORAL_DETECTIONS are imported consistently with the existing import style. These imports are necessary for the new test cases added later in the file.


Line range hint 1-331: Overall, good additions to test coverage, but assertions need improvement.

The changes to this file enhance the test suite by adding new cases for classifications and temporal detections. These additions are valuable for ensuring the getBubbles function handles these new data types correctly. The structure and style of the new tests are consistent with existing ones, which is commendable.

However, both new test cases are missing assertions to verify the results of the getBubbles calls. Adding these assertions, as suggested in the previous comments, will significantly improve the effectiveness of these tests and ensure that the function behaves as expected for these new data types.

These changes align well with the PR objective of addressing issues related to Classifications and TemporalDetections in the FiftyOne application. By improving test coverage for these components, we can better ensure their proper functionality and prevent future regressions.

To ensure comprehensive test coverage, let's verify if there are any other files that might need similar test updates:

This script will help identify other files that might need similar test updates or implementations related to Classifications and TemporalDetections.

✅ Verification successful

Verification Complete: No Additional Test Files Require Updates.

The executed scripts confirmed that there are no other test files within app/packages/looker/src/ that mention Classifications or TemporalDetections. This means that the current test coverage for these components is comprehensive within the scope of the reviewed files.

The initial review comment about enhancing the assertions in bubbles.test.ts remains pertinent to ensure robust validation of the getBubbles function.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find other test files that might need updates for Classifications and TemporalDetections

# Search for test files that mention Classifications or TemporalDetections
echo "Test files that might need updates:"
rg -l --type ts "Classifications|TemporalDetections" "app/packages/looker/src/**/*.test.ts"

# Search for non-test files that use Classifications or TemporalDetections
echo "\nNon-test files using Classifications or TemporalDetections:"
rg -l --type ts "Classifications|TemporalDetections" "app/packages/looker/src/**/*.ts" | grep -v ".test.ts"

Length of output: 564


Script:

#!/bin/bash
# Description: Find other test files that might need updates for Classifications and TemporalDetections

# Search for test files that mention Classifications or TemporalDetections
echo "Test files that might need updates:"
fd --type f --extension ts --glob '*.test.ts' | xargs rg --files-with-matches "Classifications|TemporalDetections"

# Search for non-test files that use Classifications or TemporalDetections
echo "\nNon-test files using Classifications or TemporalDetections:"
fd --type f --extension ts --exclude '*.test.ts' | xargs rg --files-with-matches "Classifications|TemporalDetections"

Length of output: 790

@@ -54,14 +54,14 @@ export const getBubbles = (
}

if (field.embeddedDocType === withPath(LABELS_PATH, CLASSIFICATIONS)) {
out.values = out.values.flatMap(
out.values = unwind(field.dbField, out.values).flatMap(
Copy link
Contributor

Choose a reason for hiding this comment

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

What does out.values look like? Flat map should unnest arrays so it's weird that you would need to unwind first

Copy link
Contributor Author

Choose a reason for hiding this comment

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

out.values is a list or single value of potentially renderable field data. flatMap flattens the nested classifications

@sashankaryal sashankaryal self-requested a review October 4, 2024 17:36
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!

@benjaminpkane benjaminpkane merged commit b481bf3 into release/v1.0.1 Oct 4, 2024
11 checks passed
@benjaminpkane benjaminpkane deleted the bugfix/4890 branch October 4, 2024 17:43
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.

3 participants