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

add set_group_slice operator #4844

Merged
merged 3 commits into from
Sep 26, 2024
Merged

add set_group_slice operator #4844

merged 3 commits into from
Sep 26, 2024

Conversation

imanjra
Copy link
Contributor

@imanjra imanjra commented Sep 25, 2024

What changes are proposed in this pull request?

add set_group_slice operator and use it in delete/rename group operation

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

Using delete/rename group operator

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

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 operator, Set Group Slice, allowing users to set group slices more effectively.
    • Added a method to set group slices within the application context.
  • Improvements

    • Updated the Rename Group Slice and Delete Group Slice operations for more efficient dataset state management after renaming and deleting group slices.
    • Enhanced error handling in the group_slice method to prevent unnecessary errors when the slice name is not provided.

@imanjra imanjra requested review from brimoor and a team September 25, 2024 21:24
Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

Warning

Rate limit exceeded

@brimoor has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 41 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between cbb8b15 and 0cf14c7.

Walkthrough

The pull request introduces a new SetGroupSlice class in the built-in-operators.ts file, which extends the Operator class and includes methods for configuration, hooks, input resolution, and execution. Additionally, modifications are made to the RenameGroupSlice and DeleteGroupSlice classes in builtin.py to update how group slices are managed during operations. Lastly, a new set_group_slice method is added in operations.py to facilitate setting group slices within the application context.

Changes

File Path Change Summary
app/packages/operators/src/built-in-operators.ts Added SetGroupSlice class with methods for configuration, hooks, input resolution, and execution. Updated registerBuiltInOperators to include SetGroupSlice.
fiftyone/operators/builtin.py Modified execute methods in RenameGroupSlice and DeleteGroupSlice to directly manage group slices instead of triggering dataset reloads.
fiftyone/operators/operations.py Added set_group_slice method to set group slices within the application context.
fiftyone/core/dataset.py Updated group_slice method to refine error handling for slice_name.

Possibly related PRs

Suggested labels

app

Poem

In the fields where slices play,
A new group joins the fray!
With hooks and methods, oh so bright,
Setting paths, making things right.
Hops of joy, a code delight! 🐇✨


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)
fiftyone/operators/operations.py (1)

632-638: LGTM! Consider enhancing the docstring.

The implementation of set_group_slice looks good and aligns with the PR objectives. It follows the pattern of other methods in the class for triggering events.

Consider enhancing the docstring to provide more context about what a "group slice" is and how it relates to group operations. This would improve the method's self-documentation. For example:

def set_group_slice(self, slice):
    """Set the group slice in the App.

    This method is used to update the current group slice, which is crucial
    for operations like deleting or renaming groups.

    Args:
        slice: the group slice to set, typically a dict containing group
               information
    """
    return self._ctx.trigger("set_group_slice", {"slice": slice})
app/packages/operators/src/built-in-operators.ts (1)

1228-1249: LGTM! Consider adding error handling and documentation.

The SetGroupSlice class implementation looks good and follows the pattern of other operators. However, consider the following improvements:

  1. Add error handling in the execute method to catch and handle potential exceptions.
  2. Add JSDoc comments to explain the purpose of the class and its methods, especially the concept of a "group slice".
  3. Decide whether this operator should be listed or unlisted in the UI (the commented out unlisted: true in the config method).

Here's a suggested improvement for the execute method:

async execute(ctx: ExecutionContext): Promise<void> {
  try {
    const { slice } = ctx.params;
    if (typeof slice !== 'string' || slice.trim() === '') {
      throw new Error('Invalid slice parameter');
    }
    ctx.hooks.setSlice(slice);
  } catch (error) {
    console.error('Error in SetGroupSlice execute:', error);
    throw error; // or handle it as appropriate for your application
  }
}
fiftyone/operators/builtin.py (1)

1568-1570: Enhanced group slice handling after deletion with a suggestion

The changes in the execute method of DeleteGroupSlice class significantly improve the handling of group slices after deletion. By selecting the first available group slice and setting it as the current one before reloading the dataset, it ensures that the UI always has a valid group slice selected. This change aligns well with the PR objectives of enhancing group operations functionality.

However, consider handling the edge case where all group slices are deleted. You might want to add a check to ensure ctx.dataset.group_slices is not empty before accessing its first element.

Consider adding a check for empty group slices:

-first_group_slice = ctx.dataset.group_slices[0]
-ctx.ops.set_group_slice(first_group_slice)
-ctx.ops.reload_dataset()
+if ctx.dataset.group_slices:
+    first_group_slice = ctx.dataset.group_slices[0]
+    ctx.ops.set_group_slice(first_group_slice)
+else:
+    # Handle the case when all group slices are deleted
+    # For example, you might want to set a default view or clear the current slice
+    ctx.ops.set_group_slice(None)
+ctx.ops.reload_dataset()
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4845d52 and a0c4d01.

📒 Files selected for processing (3)
  • app/packages/operators/src/built-in-operators.ts (2 hunks)
  • fiftyone/operators/builtin.py (2 hunks)
  • fiftyone/operators/operations.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/operators/src/built-in-operators.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 not posted (2)
app/packages/operators/src/built-in-operators.ts (1)

1297-1297: LGTM! SetGroupSlice operator successfully registered.

The addition of _registerBuiltInOperator(SetGroupSlice); to the registerBuiltInOperators function is correct and follows the established pattern for registering new operators. This ensures that the new SetGroupSlice operator will be available for use in the application.

fiftyone/operators/builtin.py (1)

1521-1522: Improved group slice handling after renaming

The changes in the execute method of RenameGroupSlice class enhance the handling of group slices after renaming. By directly setting the group slice to the new name and then reloading the dataset, it ensures that the UI is updated with the correct group slice selection. This change provides more precise control and aligns well with the PR objectives of improving group operations functionality.

brimoor
brimoor previously approved these changes Sep 25, 2024
Copy link
Contributor

@brimoor brimoor 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! I left a @todo for future work but that can be out of scope for now

@brimoor brimoor changed the base branch from develop to release/v1.0.0 September 26, 2024 04:22
@brimoor brimoor dismissed their stale review September 26, 2024 04:22

The base branch was changed.

@brimoor brimoor merged commit 0b928cf into release/v1.0.0 Sep 26, 2024
13 checks passed
@brimoor brimoor deleted the bugfix/grp-slice-op branch September 26, 2024 12:28
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