Skip to content

Commit

Permalink
[DAR-1562][External] Allow pulling of unpopulated required property a…
Browse files Browse the repository at this point in the history
…nnotations (#825)

* Allow SelectedProperty frame_index to be None to allow pull() of non-populated required properties

* Black & ruff formatting / linting

* Added data to test unpopulated required properties

* Added unit test

* Improved test
  • Loading branch information
JBWilkie authored May 3, 2024
1 parent 6fea3ab commit 92ef9db
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 109 deletions.
12 changes: 4 additions & 8 deletions darwin/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,13 @@ def __init__(
super().__init__("Complex polygons not yet supported for dataloop import")


class ExportException(DarwinException):
...
class ExportException(DarwinException): ...


class ExportException_CouldNotAssembleOutputPath(ExportException):
...
class ExportException_CouldNotAssembleOutputPath(ExportException): ...


class ExportException_CouldNotBuildOutput(ExportException):
...
class ExportException_CouldNotBuildOutput(ExportException): ...


class ExportException_CouldNotWriteFile(ExportException):
...
class ExportException_CouldNotWriteFile(ExportException): ...
12 changes: 7 additions & 5 deletions darwin/exporter/formats/yolo_segmented.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@ def _handle_polygon(

except KeyError as exc:
logger.warn(
f"Skipped annotation at index {annotation_index} because an"
"expected key was not found in the data."
f"Error occured while calculating point at index {last_point}."
if last_point
else "Error occured while enumerating points.",
(
f"Skipped annotation at index {annotation_index} because an"
"expected key was not found in the data."
f"Error occured while calculating point at index {last_point}."
if last_point
else "Error occured while enumerating points."
),
exc_info=exc,
)
return False
Expand Down
6 changes: 3 additions & 3 deletions darwin/future/core/items/archive_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def archive_list_of_items(
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
"dataset_ids": (
dataset_ids if isinstance(dataset_ids, list) else [dataset_ids]
),
**filters,
}
}
Expand Down
6 changes: 3 additions & 3 deletions darwin/future/core/items/assign_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def assign_items(
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
"dataset_ids": (
dataset_ids if isinstance(dataset_ids, list) else [dataset_ids]
),
**filters,
},
"assignee_id": assignee_id,
Expand Down
6 changes: 3 additions & 3 deletions darwin/future/core/items/delete_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def delete_list_of_items(
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
"dataset_ids": (
dataset_ids if isinstance(dataset_ids, list) else [dataset_ids]
),
**filters,
}
}
Expand Down
6 changes: 3 additions & 3 deletions darwin/future/core/items/move_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def move_items_to_stage(
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
"dataset_ids": (
dataset_ids if isinstance(dataset_ids, list) else [dataset_ids]
),
**filters,
},
"stage_id": str(stage_id),
Expand Down
6 changes: 3 additions & 3 deletions darwin/future/core/items/move_items_to_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def move_list_of_items_to_folder(
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
"dataset_ids": (
dataset_ids if isinstance(dataset_ids, list) else [dataset_ids]
),
**filters,
},
"path": path,
Expand Down
6 changes: 3 additions & 3 deletions darwin/future/core/items/restore_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def restore_list_of_items(
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
"dataset_ids": (
dataset_ids if isinstance(dataset_ids, list) else [dataset_ids]
),
**filters,
}
}
Expand Down
6 changes: 3 additions & 3 deletions darwin/future/core/items/set_item_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def set_item_layout(
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
"dataset_ids": (
dataset_ids if isinstance(dataset_ids, list) else [dataset_ids]
),
**filters,
},
"layout": dict(layout),
Expand Down
6 changes: 3 additions & 3 deletions darwin/future/core/items/set_item_priority.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def set_item_priority(
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
"dataset_ids": (
dataset_ids if isinstance(dataset_ids, list) else [dataset_ids]
),
**filters,
},
"priority": priority,
Expand Down
6 changes: 3 additions & 3 deletions darwin/future/core/items/set_stage_to_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def set_stage_to_items(
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
"dataset_ids": (
dataset_ids if isinstance(dataset_ids, list) else [dataset_ids]
),
**filters,
},
"stage_id": stage_id,
Expand Down
6 changes: 3 additions & 3 deletions darwin/future/core/items/tag_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def tag_items(
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
"dataset_ids": (
dataset_ids if isinstance(dataset_ids, list) else [dataset_ids]
),
**filters,
},
"annotation_class_id": tag_id,
Expand Down
6 changes: 3 additions & 3 deletions darwin/future/core/items/untag_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def untag_items(
), "No parameters provided, please provide at least one non-dataset id filter"
payload = {
"filters": {
"dataset_ids": dataset_ids
if isinstance(dataset_ids, list)
else [dataset_ids],
"dataset_ids": (
dataset_ids if isinstance(dataset_ids, list) else [dataset_ids]
),
**filters,
},
"annotation_class_id": tag_id,
Expand Down
3 changes: 1 addition & 2 deletions darwin/future/core/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@


class Implements_str(Protocol):
def __str__(self) -> str:
...
def __str__(self) -> str: ...


Stringable = Union[str, Implements_str]
Expand Down
2 changes: 1 addition & 1 deletion darwin/future/data_objects/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class SelectedProperty(DefaultDarwin):
value (str): Value of the property
"""

frame_index: int
frame_index: Optional[int] = None
name: str
type: Optional[str] = None
value: Optional[str] = None
80 changes: 50 additions & 30 deletions darwin/future/meta/objects/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ class Item(MetaBase[ItemCore]):
def delete(self) -> None:
team_slug, dataset_id = (
self.meta_params["team_slug"],
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"],
(
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"]
),
)
assert isinstance(team_slug, str)
dataset_id = cast(Union[int, List[int]], dataset_id)
Expand All @@ -72,9 +74,11 @@ def delete(self) -> None:
def move_to_folder(self, path: str) -> None:
team_slug, dataset_id = (
self.meta_params["team_slug"],
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"],
(
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"]
),
)
assert isinstance(team_slug, str)
dataset_id = cast(Union[int, List[int]], dataset_id)
Expand All @@ -84,9 +88,11 @@ def move_to_folder(self, path: str) -> None:
def set_priority(self, priority: int) -> None:
team_slug, dataset_id = (
self.meta_params["team_slug"],
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"],
(
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"]
),
)
assert isinstance(team_slug, str)
dataset_id = cast(Union[int, List[int]], dataset_id)
Expand All @@ -96,9 +102,11 @@ def set_priority(self, priority: int) -> None:
def restore(self) -> None:
team_slug, dataset_id = (
self.meta_params["team_slug"],
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"],
(
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"]
),
)
assert isinstance(team_slug, str)
dataset_id = cast(Union[int, List[int]], dataset_id)
Expand All @@ -108,9 +116,11 @@ def restore(self) -> None:
def archive(self) -> None:
team_slug, dataset_id = (
self.meta_params["team_slug"],
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"],
(
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"]
),
)
assert isinstance(team_slug, str)
dataset_id = cast(Union[int, List[int]], dataset_id)
Expand All @@ -120,9 +130,11 @@ def archive(self) -> None:
def set_layout(self, layout: ItemLayout) -> None:
team_slug, dataset_id = (
self.meta_params["team_slug"],
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"],
(
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"]
),
)
assert isinstance(team_slug, str)
assert isinstance(layout, ItemLayout)
Expand All @@ -143,9 +155,11 @@ def assign(self, assignee_id: int, workflow_id: str | None = None) -> None:
assert isinstance(workflow_id, str)
team_slug, dataset_id = (
self.meta_params["team_slug"],
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"],
(
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"]
),
)
assert isinstance(team_slug, str)

Expand All @@ -158,9 +172,11 @@ def assign(self, assignee_id: int, workflow_id: str | None = None) -> None:
def tag(self, tag_id: int) -> None:
team_slug, dataset_id = (
self.meta_params["team_slug"],
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"],
(
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"]
),
)
assert isinstance(team_slug, str)
if not isinstance(tag_id, int):
Expand All @@ -172,9 +188,11 @@ def tag(self, tag_id: int) -> None:
def untag(self, tag_id: int) -> None:
team_slug, dataset_id = (
self.meta_params["team_slug"],
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"],
(
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"]
),
)
assert isinstance(team_slug, str)
if not isinstance(tag_id, int):
Expand All @@ -200,9 +218,11 @@ def set_stage(
assert isinstance(workflow_id, str)
team_slug, dataset_id = (
self.meta_params["team_slug"],
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"],
(
self.meta_params["dataset_id"]
if "dataset_id" in self.meta_params
else self.meta_params["dataset_ids"]
),
)
assert isinstance(team_slug, str)

Expand Down
9 changes: 8 additions & 1 deletion darwin/future/tests/data_objects/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from darwin.future.data_objects.properties import MetaDataClass
from darwin.future.data_objects.properties import MetaDataClass, SelectedProperty


@pytest.fixture
Expand Down Expand Up @@ -35,3 +35,10 @@ def test_properties_metadata_fails() -> None:
path = Path("darwin/future/tests/data/does_not_exist")
with pytest.raises(FileNotFoundError):
MetaDataClass.from_path(path)


def test_can_parse_unpopulated_required_properties() -> None:
selected_property = SelectedProperty(
frame_index=None, name="name", type="type", value=None
)
assert selected_property is not None
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
class InvalidValueForTest:
...
class InvalidValueForTest: ...
Loading

0 comments on commit 92ef9db

Please sign in to comment.