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

Cherry pick builtin use lists #5423

Merged
merged 3 commits into from
Jan 22, 2025
Merged

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Jan 22, 2025

Cherry pick #5379 for release.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced field handling in dataset operations
    • Improved support for nested field management
    • More flexible field selection in operators
  • Improvements

    • Added support for multiple list fields during summary creation
    • Refined path filtering for field operations
    • Updated input validation for field-related actions
  • Bug Fixes

    • Improved error handling for field name selections
    • Fixed limitations in field manipulation across various operators

@brimoor brimoor requested a review from ritch January 22, 2025 18:03
Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Walkthrough

The pull request introduces modifications across three files: fiftyone/core/dataset.py, fiftyone/core/odm/mixins.py, and plugins/operators/__init__.py. The changes primarily focus on enhancing field handling capabilities, including improvements to summary field creation, path filtering, and operator input processing. The modifications aim to provide more flexibility in managing dataset fields, supporting nested field operations, and improving user interaction with field-related functionalities.

Changes

File Change Summary
fiftyone/core/dataset.py Modified create_summary_field to unwind all list fields instead of just the first one
fiftyone/core/odm/mixins.py Added _remove_nested_paths function to filter out nested paths in field operations
plugins/operators/__init__.py Updated multiple operator input functions to support nested fields, multiple field selections, and improved error handling

Sequence Diagram

sequenceDiagram
    participant User
    participant Operators
    participant Dataset
    participant ODM

    User->>Operators: Select field operations
    Operators->>Dataset: Process field requests
    Dataset->>ODM: Filter and validate paths
    ODM-->>Dataset: Return filtered paths
    Dataset-->>Operators: Execute field operations
    Operators-->>User: Display results
Loading

Possibly related PRs

Suggested reviewers

  • ritch
  • minhtuev

Poem

🐰 A Rabbit's Ode to Field Flexibility

In datasets where paths twist and twine,
Our code now dances, line by line
Nested fields, no longer confined
With operators smart and refined
Flexibility's our design! 🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 (7)
plugins/operators/__init__.py (5)

259-261: Refactor repeated validation logic into a helper function

The validation code that checks if field_name exists in schema and handles the error messaging is repeated multiple times across the codebase. Consider refactoring this repeated logic into a helper function to improve maintainability and reduce code duplication.

Here’s how you might refactor the repeated code:

def _validate_field_name(field_name, schema, field_prop, field_type):
    if field_name is None:
        return True
    if field_name not in schema and "." not in field_name:
        field_prop.invalid = True
        field_prop.error_message = f"{field_type} field '{field_name}' does not exist"
        return True
    return False

And replace the repeated blocks with:

if _validate_field_name(field_name, schema, field_prop, "Sample"):
    return

Also applies to: 377-379, 454-456


647-647: Simplify dictionary iteration by removing .keys()

In the line for key in schema.keys():, it's more Pythonic and efficient to iterate directly over the dictionary keys using for key in schema:.

Apply this diff to simplify the code:

-for key in schema.keys():
+for key in schema:
🧰 Tools
🪛 Ruff (0.8.2)

647-647: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)


755-755: Simplify dictionary iteration by removing .keys()

Similarly, in this loop, you can iterate directly over the dictionary:

Apply this diff:

-for key in schema.keys():
+for key in schema:
🧰 Tools
🪛 Ruff (0.8.2)

755-755: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)


907-907: Simplify dictionary iteration by removing .keys()

Consider removing .keys() to iterate over the dictionary keys directly:

Apply this diff:

-for key in schema.keys():
+for key in schema:
🧰 Tools
🪛 Ruff (0.8.2)

907-907: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)


982-982: Simplify dictionary iteration by removing .keys()

It's more concise to iterate over the dictionary without .keys():

Apply this diff:

-for key in schema.keys():
+for key in schema:
🧰 Tools
🪛 Ruff (0.8.2)

982-982: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

fiftyone/core/odm/mixins.py (1)

1872-1878: Optimize _remove_nested_paths function for scalability

The _remove_nested_paths function uses a nested loop, which can lead to performance issues with large lists of paths. Consider optimizing the function to improve efficiency.

Here's an optimized version using a set for faster lookups:

-def _remove_nested_paths(paths):
-    return [
-        path
-        for path in paths
-        if not any(path.startswith(p + ".") for p in paths)
-    ]
+def _remove_nested_paths(paths):
+    path_set = set(paths)
+    result = []
+    for path in paths:
+        parent = path
+        while '.' in parent:
+            parent = parent.rsplit('.', 1)[0]
+            if parent in path_set:
+                break
+        else:
+            result.append(path)
+    return result
fiftyone/core/dataset.py (1)

1967-1968: Improved list field handling in summary field creation.

The change to iterate and unwind all list fields is a significant improvement over only unwinding the first list field. This ensures proper handling of multiple list fields when creating summary fields.

Consider adding a comment explaining that all list fields must be unwound to properly handle cases where samples contain multiple list fields that need to be summarized.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4d4bbb8 and 26babad.

📒 Files selected for processing (3)
  • fiftyone/core/dataset.py (1 hunks)
  • fiftyone/core/odm/mixins.py (4 hunks)
  • plugins/operators/__init__.py (20 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
plugins/operators/__init__.py

647-647: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)


755-755: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)


907-907: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)


982-982: Use key in dict instead of key in dict.keys()

Remove .keys()

(SIM118)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test / test-app
  • GitHub Check: build / build

@brimoor brimoor merged commit dad1c09 into release/v1.3.0 Jan 22, 2025
10 of 14 checks passed
@brimoor brimoor deleted the cherry-pick-builtin-use-lists branch January 22, 2025 19:16
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.

2 participants