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

Revert 5407 #5429

Merged
merged 1 commit into from
Jan 24, 2025
Merged

Revert 5407 #5429

merged 1 commit into from
Jan 24, 2025

Conversation

kaixi-wang
Copy link
Contributor

@kaixi-wang kaixi-wang commented Jan 24, 2025

What changes are proposed in this pull request?

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

(Details)

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

Release Notes

  • Breaking Changes

    • Removed SampleView from public module imports
    • Removed first(), last(), head(), tail(), and one() methods from DatasetView
  • Improvements

    • Enhanced SampleCollection methods for retrieving samples
    • Updated Dataset methods to simplify sample retrieval logic
    • Improved error handling when accessing samples in collections
  • Testing

    • Removed related unit tests for sample retrieval methods

These changes modify how samples are accessed and retrieved in the dataset, potentially requiring updates to existing code that uses these methods.

@kaixi-wang kaixi-wang self-assigned this Jan 24, 2025
Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Walkthrough

This pull request introduces significant changes to the FiftyOne library's core functionality, focusing on sample retrieval methods across multiple files. The modifications involve removing SampleView from the public interface, implementing concrete methods for sample collection operations, and refactoring how first, last, head, and tail samples are retrieved in dataset and view classes. The changes simplify the sample access methods and update the implementation to provide more direct and consistent sample retrieval mechanisms.

Changes

File Change Summary
fiftyone/__public__.py Removed SampleView import from .core.sample module
fiftyone/core/collections.py Implemented concrete methods for first(), last(), head(), tail(), and one() in SampleCollection class
fiftyone/core/dataset.py Removed _get_first() method, refactored first(), last(), head(), tail(), and one() methods
fiftyone/core/view.py Removed first(), last(), head(), tail(), and one() methods from DatasetView class
tests/unittests/dataset_tests.py Removed test_first_last_head_tail and test_first_last_head_tail_empty test methods

Possibly related PRs

Suggested reviewers

  • brimoor

Poem

🐰 Hopping through code with glee,
Sample methods now set free!
No more views that complicate,
Retrieval methods now first-rate
A rabbit's dance of refactoring spree! 🚀

✨ 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

@jleven jleven left a comment

Choose a reason for hiding this comment

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

Thank you

@kaixi-wang kaixi-wang merged commit 448177d into release/v1.3.0 Jan 24, 2025
11 of 12 checks passed
@kaixi-wang kaixi-wang deleted the kacey/revert-opt branch January 24, 2025 02:22
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 (4)
fiftyone/core/dataset.py (1)

1237-1241: Raise exceptions with raise ... from err to preserve the original traceback.

A static analysis hint suggests re-raising from the original exception for better debugging clarity:

-    except ValueError:
-        raise ValueError("%s is empty" % self.__class__.__name__)
+    except ValueError as e:
+        raise ValueError("%s is empty" % self.__class__.__name__) from e
🧰 Tools
🪛 Ruff (0.8.2)

1239-1239: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

fiftyone/__public__.py (1)

166-166: Remove unused import

Static analysis tools indicate that the Sample import is not used. Removing it will clean up the code and can help avoid confusion.

- from .core.sample import Sample
🧰 Tools
🪛 Ruff (0.8.2)

166-166: .core.sample.Sample imported but unused

Remove unused import: .core.sample.Sample

(F401)

fiftyone/core/collections.py (2)

926-929: Add error context when raising ValueError

The error handling should preserve the context of the original error by using raise ... from None syntax.

 try:
     return next(iter(self))
 except StopIteration:
-    raise ValueError("%s is empty" % self.__class__.__name__)
+    raise ValueError("%s is empty" % self.__class__.__name__) from None
🧰 Tools
🪛 Ruff (0.8.2)

929-929: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


Line range hint 971-1031: Add error context when raising ValueError and improve error message

The error handling should preserve the context of the original error and provide more descriptive error messages.

 try:
     sample = next(matches)
 except StopIteration:
-    raise ValueError("No samples match the given expression")
+    raise ValueError(
+        "No samples match the given expression '%s'" % expr
+    ) from None

 if exact:
     try:
         next(matches)
         raise ValueError(
-            "Expected one matching sample, but found %d matches"
-            % len(view)
+            "Expected exactly one matching sample for expression '%s', but found %d matches"
+            % (expr, len(view))
         )
     except StopIteration:
         pass
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2b843b9 and 7e610dc.

📒 Files selected for processing (5)
  • fiftyone/__public__.py (1 hunks)
  • fiftyone/core/collections.py (5 hunks)
  • fiftyone/core/dataset.py (6 hunks)
  • fiftyone/core/view.py (0 hunks)
  • tests/unittests/dataset_tests.py (0 hunks)
💤 Files with no reviewable changes (2)
  • fiftyone/core/view.py
  • tests/unittests/dataset_tests.py
🧰 Additional context used
🪛 Ruff (0.8.2)
fiftyone/__public__.py

166-166: .core.sample.Sample imported but unused

Remove unused import: .core.sample.Sample

(F401)

fiftyone/core/collections.py

929-929: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


1019-1019: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

fiftyone/core/dataset.py

1239-1239: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test / test-app
  • GitHub Check: build / build
  • GitHub Check: build
🔇 Additional comments (9)
fiftyone/core/dataset.py (6)

1228-1228: No issues found on this line. Good usage of super().first().


1255-1258: Clear and concise data extraction in the head method.


1272-1275: Well-structured list comprehension in the tail method.


1306-1306: No issues; example usage in the docstring is fine.


1318-1319: Straightforward use of match() and _aggregate() for filtering.


1330-1331: String formatting logic is acceptable.

fiftyone/core/collections.py (3)

938-938: LGTM: Efficient implementation of last()

The implementation correctly returns the last element by taking a slice of the last element and using first() to retrieve it.


950-952: LGTM: Clear docstring and implementation for head()

The docstring accurately describes the return type and the implementation efficiently returns the first N samples as a list.


964-966: LGTM: Clear docstring and implementation for tail()

The docstring accurately describes the return type and the implementation efficiently returns the last N samples as a list.

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