Skip to content

Commit

Permalink
[PY-622][PY-626][PY-665] Import Properties (create/update) while impo…
Browse files Browse the repository at this point in the history
…rting annotations (#759)

* _import_properties WIP

* fix tests for is_properties_enabled

* add more logic

* remove metadata file edge cases

* update tests

* fix import logic

* rm breakpoint

* update importer - fix client

* remove print

* update prints

* udpate metadata_path check

* update propertyvalue create logic

* [PY-626] Updates to import endpoint - `annotation_properties` (#760)

* handling properties data while importing annotations

* add tests for _handle_annotation_data

* update importer - add annotations_properties in payload of import annotations

* update importer - rm _handle_properties code

* fix test

* update test

* fix indent

* add the missing return value

* fix issues with multi_select create_property

* rm `_msg` variable used in ValueError as they are not used again.

* update list lookup -> to set for faster lookups

* update `annotation_id_property_map` keys are moved from str -> tuple[str, str]

* created a doc-block for _import_properties fn

* [PY-665] - Update property-value object structure to support un-nested value field (#769)

* update nested value changes for property-value objects

* fix tests + fix linting

* rm property field from PropertyValue object

* add description & rm type in PropertyValue

* update test-metadata files
  • Loading branch information
saurbhc authored Jan 25, 2024
1 parent 0e0ad60 commit 2ab1cef
Show file tree
Hide file tree
Showing 9 changed files with 340 additions and 46 deletions.
13 changes: 8 additions & 5 deletions darwin/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
except ImportError:
NDArray = Any # type:ignore

from darwin.future.data_objects.properties import SelectedProperty
from darwin.future.data_objects.properties import PropertyType, SelectedProperty
from darwin.path_utils import construct_full_path, is_properties_enabled, parse_metadata

# Utility types
Expand Down Expand Up @@ -405,13 +405,16 @@ class Property:
name: str

# Type of the property
type: str
type: PropertyType

# Whether the property is required or not
required: bool

# Description of the property
description: Optional[str]

# Property options
options: list[dict[str, str]]
options: list[dict[str, Any]]


@dataclass
Expand Down Expand Up @@ -475,10 +478,10 @@ def split_paths_by_metadata(
tuple[Path, Optional[list[PropertyClass]]]
A tuple containing the path to the metadata file and the list of property classes.
"""
if not is_properties_enabled(path, dir, filename):
metadata_path = is_properties_enabled(path, dir, filename)
if isinstance(metadata_path, bool):
return path, None

metadata_path = path / dir / filename
metadata = parse_metadata(metadata_path)
property_classes = parse_property_classes(metadata)

Expand Down
18 changes: 5 additions & 13 deletions darwin/future/data_objects/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import os
from pathlib import Path
from typing import Dict, List, Literal, Optional, Tuple, Union
from typing import List, Literal, Optional, Tuple

from pydantic import field_validator

Expand Down Expand Up @@ -33,9 +33,8 @@ class PropertyValue(DefaultDarwin):
"""

id: Optional[str] = None
position: Optional[int] = None
type: Literal["string"] = "string"
value: Union[Dict[str, str], str]
value: str
color: str = "auto"

@field_validator("color")
Expand All @@ -45,14 +44,6 @@ def validate_rgba(cls, v: str) -> str:
raise ValueError("Color must be in rgba format or 'auto'")
return v

@field_validator("value")
@classmethod
def validate_value(cls, v: Union[Dict[str, str], str]) -> Dict[str, str]:
"""TODO: Replace once the value.value bug is fixed in the API"""
if isinstance(v, str):
return {"value": v}
return v

def to_update_endpoint(self) -> Tuple[str, dict]:
if self.id is None:
raise ValueError("id must be set")
Expand All @@ -72,6 +63,7 @@ class FullProperty(DefaultDarwin):
"""

id: Optional[str] = None
position: Optional[int] = None
name: str
type: PropertyType
description: Optional[str] = None
Expand All @@ -93,7 +85,7 @@ def to_create_endpoint(
"type": True,
"required": True,
"annotation_class_id": True,
"property_values": {"__all__": {"type", "value", "color"}},
"property_values": {"__all__": {"value", "color"}},
"description": True,
}
)
Expand Down Expand Up @@ -157,5 +149,5 @@ class SelectedProperty(DefaultDarwin):

frame_index: int
name: str
type: str
type: Literal["string"] = "string"
value: str
Loading

0 comments on commit 2ab1cef

Please sign in to comment.