Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions darwin/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,19 +764,16 @@ def _parse_darwin_raster_annotation(annotation: dict) -> Optional[dt.Annotation]


def _parse_darwin_mask_annotation(annotation: dict) -> Optional[dt.Annotation]:
if not annotation.get("mask"):
raise ValueError("Mask annotation must have a 'mask' field")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need in this condition as it checked one more time below.

id: Optional[str] = annotation.get("id")
name: Optional[str] = annotation.get("name")
mask: Optional[dt.JSONFreeForm] = annotation.get("mask")
slot_names: Optional[List[str]] = parse_slot_names(annotation)

if not id or not name or not mask or not slot_names:
if not id or not name or mask is None or not slot_names:
raise ValueError("Mask annotation must have an 'id', 'name', 'slot_names' and 'mask' field")

if (not "sparse_rle" in mask) or (not mask["sparse_rle"]) == None:
raise ValueError("Mask annotation must have a 'sparse_rle' field containing a null value")
if ("sparse_rle" in mask) and (mask["sparse_rle"] is not None):
raise ValueError("Mask annotation field 'sparse_rle' must contain a null value")

new_annotation = dt.Annotation(
dt.AnnotationClass(name, "mask"),
Expand Down