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

Summary field and index improvements #5091

Merged
merged 2 commits into from
Nov 12, 2024
Merged

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Nov 12, 2024

Change log

  • Added support for generating summary fields for ObjectIdField and ListField
  • Improved default summary field name logic to prevent name clashes with existing fields
  • Only show valid + unindexed fields in create_index operator
  • Fixed a bug with frame-level default indexes in the builtin drop_index operator

Example usage

import fiftyone as fo
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset("quickstart-video")

# None of these were previously possible, now they are
dataset.create_summary_field("tags")
dataset.create_summary_field("id")
dataset.create_summary_field("frames.detections.detections.id")

Summary by CodeRabbit

  • New Features

    • Enhanced summary field creation with improved validation for field types, including support for ObjectIdField.
    • Asynchronous index creation with the addition of a wait parameter.
  • Bug Fixes

    • Improved error handling and user feedback for invalid input when creating or renaming fields.
  • Refactor

    • Simplified input resolution methods and sorting logic for better clarity and maintainability.

@brimoor brimoor requested a review from minhtuev November 12, 2024 15:42
Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

Walkthrough

The changes introduce a new private method _get_summarized_fields_map in the Dataset class for mapping summarized fields based on the dataset's schema. Modifications to the create_summary_field method include checks for list fields and handling of ObjectIdField. In the fiftyone/operators/builtin.py file, updates enhance field type validation in CreateSummaryField and UpdateSummaryField, refine logic for summarizing fields, and improve error handling across various methods. The overall structure remains intact, focusing on enhancing summary field management and input validation.

Changes

File Path Change Summary
fiftyone/core/dataset.py - Added method _get_summarized_fields_map in Dataset.
- Updated create_summary_field to include checks for list fields and handle ObjectIdField.
- Modified _get_default_summary_field_name for uniqueness.
fiftyone/operators/builtin.py - Updated CreateSummaryField and UpdateSummaryField for field type validation.
- Refined logic for summarizing fields and filtering eligible fields in CreateIndex.
- Enhanced error handling across various methods.

Possibly related PRs

Suggested labels

feature, bug

Suggested reviewers

  • swheaton
  • ritch

🐰 In the meadow, fields do bloom,
With summaries that make room,
For data's tales, both bright and clear,
New checks and maps, we hold dear.
Hops of joy, as changes flow,
In our dataset, watch it grow! 🌼


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.

fo.FloatField,
fo.IntField,
fo.DateField,
fo.DateTimeField,
Copy link
Contributor

Choose a reason for hiding this comment

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

FrameNumberField could be apply here. I only note it because it came up in the lightning backend. Reported by @minhtuev

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the backend we have the luxury of using isinstance, which understands that FrameNumberField is a subclass of IntField. So we're all set 😎

fo.StringField,
fo.BooleanField,
fo.ObjectIdField,
)
numeric_field_types = (
fo.FloatField,
fo.IntField,
fo.DateField,
fo.DateTimeField,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1795427 and 1e12882.

📒 Files selected for processing (1)
  • fiftyone/operators/builtin.py (18 hunks)
🔇 Additional comments (4)
fiftyone/operators/builtin.py (4)

1031-1041: LGTM! Clear separation of field types and support for ObjectIdField

The changes improve code organization by clearly separating field types into categorical and numeric groups, while adding support for ObjectIdField as mentioned in the PR objectives.

Also applies to: 1204-1215


1086-1086: Performance improvement: Asynchronous index creation

The addition of wait=False makes index creation asynchronous, which can improve responsiveness by not blocking the operation.


1106-1107: Bug fix: Correct frame-level default index path construction

The fix properly constructs the frame-level default index paths by correctly prefixing them, addressing the bug mentioned in the PR objectives.


1161-1170: Improved field name handling with better null checks

The changes enhance field name handling by:

  1. Adding a reusable _get_dynamic helper function
  2. Improving null checks for field names
  3. Making the code more maintainable

This aligns with the PR objective of improving default summary field name logic.

Also applies to: 1187-1191

Comment on lines +71 to +73
path_keys = list(schema.keys())
path_selector = types.AutocompleteView()
for key in sorted(schema.keys()):
for key in path_keys:
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider refactoring repeated field selection logic

The same pattern for field selection appears in multiple places:

  1. Converting keys to a list
  2. Creating an AutocompleteView
  3. Adding choices in a loop

Consider extracting this into a helper function to reduce code duplication.

Example implementation:

def create_field_selector(keys):
    """Create an AutocompleteView for the given field keys.
    
    Args:
        keys: Iterable of field keys
        
    Returns:
        types.AutocompleteView: The configured selector
    """
    field_selector = types.AutocompleteView()
    for key in sorted(keys):  # Sort for consistent ordering
        field_selector.add_choice(key, label=key)
    return field_selector

Then use it like:

-    field_keys = list(schema.keys())
-    field_selector = types.AutocompleteView()
-    for key in field_keys:
-        field_selector.add_choice(key, label=key)
+    field_selector = create_field_selector(schema.keys())

Also applies to: 245-246, 373-374, 460-462, 556-558, 672-674, 772-774, 915-917, 985-987

Copy link
Contributor

@minhtuev minhtuev left a comment

Choose a reason for hiding this comment

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

@@ -1125,13 +1158,16 @@ def resolve_input(self, ctx):

def execute(self, ctx):
path = ctx.params["path"]
field_name = ctx.params.get("field_name", None)
_, field_name = _get_dynamic(ctx.params, "field_name", path, None)
Copy link
Contributor

@minhtuev minhtuev Nov 12, 2024

Choose a reason for hiding this comment

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

Do we pass in any default value that is not None? We can potentially remove the arg to reduce confusion.

@minhtuev minhtuev merged commit 2b28b83 into release/v1.1.0 Nov 12, 2024
13 checks passed
@minhtuev minhtuev deleted the summary-field-tweaks branch November 12, 2024 19:35
@minhtuev
Copy link
Contributor

Merging so that we can create an OSS -> Teams merge PR

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.

3 participants