-
Notifications
You must be signed in to change notification settings - Fork 680
Patch Sample and Field endpoints #6411
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ac55b3e
initial commit
j053y c0b2d2c
add transform for patch value and use patch util
CamronStaley 00bd41e
check in
j053y 7e0cffc
integrate + new endpoint
CamronStaley 7bdda4e
typo
CamronStaley 5c8fa36
add logging
CamronStaley 510e131
add tests for new endpoint
CamronStaley 6c7e6cc
refactor
j053y 0a6c5c9
fix value transform
CamronStaley 0907281
refactor
j053y 59a702b
allow transform function in parse
CamronStaley d0ad099
fix typo
CamronStaley ab6f0c0
docstrings and tests
j053y b100723
remove unused import
j053y 61bfed1
refactor patches
j053y ff56964
remnove old file
j053y cb3cc18
code rabbit
j053y 4878c98
rabbit
CamronStaley eccc979
address code rabbit and tom
j053y ac37035
ok coderabbit enough
j053y File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| """ | ||
| FiftyOne Server utils json transform. | ||
|
|
||
| | Copyright 2017-2025, Voxel51, Inc. | ||
| | `voxel51.com <https://voxel51.com/>`_ | ||
| | | ||
| """ | ||
|
|
||
| import fiftyone.server.utils.json_transform.types # auto-register resource types | ||
| from fiftyone.server.utils.json_transform.transform import transform |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """Transform a json value. | ||
|
|
||
| | Copyright 2017-2025, Voxel51, Inc. | ||
| | `voxel51.com <https://voxel51.com/>`_ | ||
| | | ||
| """ | ||
| from typing import Any, Callable, Type, TypeVar | ||
|
|
||
| T = TypeVar("T") | ||
|
|
||
| REGISTRY: dict[Type[T], Callable[[dict], T]] = {} | ||
|
|
||
|
|
||
| def register( | ||
| cls: Type[T], # pylint: disable=redefined-builtin | ||
| ) -> Callable[[Callable[[dict], T]], Callable[[dict], T]]: | ||
| """Register a validator function for a resource type. | ||
|
|
||
| Args: | ||
| cls Type[T]: The resource type | ||
|
|
||
| Returns: | ||
| Callable[[Callable[[dict], T]], Callable[[dict], T]]: A decorator | ||
| that registers the decorated function as a validator for the given | ||
| resource type. | ||
| """ | ||
|
|
||
| def inner(fn: Callable[[dict], T]) -> Callable[[dict], T]: | ||
| if not callable(fn): | ||
| raise TypeError("fn must be callable") | ||
|
|
||
| if cls in REGISTRY: | ||
| raise ValueError( | ||
| f"Resource type '{cls.__name__}' validator already registered" | ||
| ) | ||
|
|
||
| REGISTRY[cls] = fn | ||
|
|
||
| return fn | ||
|
|
||
| return inner | ||
|
|
||
|
|
||
| def transform( | ||
| value: Any, | ||
| ) -> Any: | ||
| """Transforms a patch value if there is a registered transform method. | ||
| Args: | ||
| value (Any): The patch value optionally containing "_cls" key. | ||
|
|
||
| Returns: | ||
| Any: The transformed value or the original value if no transform is found. | ||
| """ | ||
| if not isinstance(value, dict): | ||
| return value | ||
|
|
||
| func = None | ||
| cls_name = value.get("_cls") | ||
| if cls_name: | ||
| func = next( | ||
| (fn for cls, fn in REGISTRY.items() if cls.__name__ == cls_name), | ||
| None, | ||
| ) | ||
| if not func: | ||
| raise ValueError(f"No transform registered for class '{cls_name}'") | ||
| return func(value) if func else value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| """Json types registery. | ||
|
|
||
| | Copyright 2017-2025, Voxel51, Inc. | ||
| | `voxel51.com <https://voxel51.com/>`_ | ||
| | | ||
| """ | ||
| from fiftyone.server.utils.json_transform.transform import register | ||
| import fiftyone.core.labels as fol | ||
|
|
||
|
|
||
| @register(fol.Classification) | ||
| def transform_classification(value: dict) -> fol.Classification: | ||
| return fol.Classification.from_dict(value) | ||
|
|
||
|
|
||
| @register(fol.Classifications) | ||
| def transform_classifications(value: dict) -> fol.Classifications: | ||
| return fol.Classifications.from_dict(value) | ||
|
|
||
|
|
||
| @register(fol.Detection) | ||
| def transform_detection(value: dict) -> fol.Detection: | ||
| return fol.Detection.from_dict(value) | ||
|
|
||
|
|
||
| @register(fol.Detections) | ||
| def transform_detections(value: dict) -> fol.Detections: | ||
| return fol.Detections.from_dict(value) | ||
|
|
||
|
|
||
| @register(fol.Polyline) | ||
| def transform_polyline(value: dict) -> fol.Polyline: | ||
| return fol.Polyline.from_dict(value) | ||
|
|
||
|
|
||
| @register(fol.Polylines) | ||
| def transform_polylines(value: dict) -> fol.Polylines: | ||
| return fol.Polylines.from_dict(value) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.