diff --git a/darwin/utils/utils.py b/darwin/utils/utils.py index e4907f50e..41572c325 100644 --- a/darwin/utils/utils.py +++ b/darwin/utils/utils.py @@ -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") - 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"),