Commit 11cb5a81 authored by Eelco van der Wel's avatar Eelco van der Wel :speech_balloon:
Browse files

Merge branch 'eelco/move-item' into 'dev'

Move Item to central schema

See merge request !252
parents 0b776152 10ce61ed
Pipeline #10744 passed with stages
in 1 minute and 29 seconds
Showing with 31 additions and 33 deletions
+31 -33
from .item import Edge, Item, ItemBase # noqa: F405, type: ignore
from .itembase import Edge, ItemBase # noqa: F405, type: ignore
from .schema import * # noqa: F405, type: ignore
......@@ -5,7 +5,22 @@
from datetime import datetime
from typing import List, Optional, Union
from pymemri.data.schema.item import Item
from pymemri.data.schema.itembase import ItemBase
class Item(ItemBase):
# Properties
id: Optional[str] = None
dateCreated: Optional[datetime] = None
dateModified: Optional[datetime] = None
dateServerModified: Optional[datetime] = None
deleted: Optional[bool] = None
externalId: Optional[str] = None
isMock: Optional[bool] = None
# Edges
language: List["Language"] = []
label: List["CategoricalPrediction"] = []
class Account(Item):
......@@ -242,6 +257,12 @@ class LabellingTask(Item):
view: List["CVUStoredDefinition"] = []
class Language(Item):
# Properties
languageCode: Optional[str] = None
languageName: Optional[str] = None
class Location(Item):
# Properties
latitude: Optional[float] = None
......
......@@ -8,7 +8,6 @@ from typing import (
Dict,
Generic,
List,
Optional,
Tuple,
Type,
TypeVar,
......@@ -26,7 +25,6 @@ from .utils import get_args, get_origin, type_or_union_to_tuple, type_to_str
if TYPE_CHECKING:
from ...pod.client import PodClient
from ._central_schema import CategoricalPrediction
SOURCE, TARGET, TYPE, EDGE_TYPE, LABEL, SEQUENCE, ALL_EDGES = (
"_source",
......@@ -117,11 +115,11 @@ class _ItemMeta(ModelMetaclass):
return cls
TargetType = TypeVar("TargetType", bound="Item")
TargetType = TypeVar("TargetType", bound="ItemBase")
class Edge(GenericModel, Generic[TargetType], smart_union=True, copy_on_model_validation=False):
source: "Item"
source: "ItemBase"
target: TargetType
name: str
......@@ -142,7 +140,7 @@ class Edge(GenericModel, Generic[TargetType], smart_union=True, copy_on_model_va
def get_target_types_as_str(cls) -> Tuple[str]:
return tuple(type_to_str(t) for t in cls.get_target_types())
@validator("target", pre=True)
@validator("target", pre=True, allow_reuse=True)
def validate_target(cls, val: Any) -> TargetType:
"""
To allow for overwriting schema classes on a different place, validator
......@@ -437,21 +435,5 @@ class ItemBase(BaseModel, metaclass=_ItemMeta, extra=Extra.forbid):
return cls(**json)
class Item(ItemBase):
id: Optional[str] = None
dateCreated: Optional[datetime] = None
dateModified: Optional[datetime] = None
dateServerModified: Optional[datetime] = None
deleted: bool = False
# TODO following edges and properties are not ItemBase properties in central schema/pod,
# Taken from old ItemBase
externalId: Optional[str] = None
isMock: Optional[bool] = None
# Edges
label: List["CategoricalPrediction"] = []
Edge.update_forward_refs()
ItemBase.update_forward_refs()
......@@ -6,8 +6,7 @@ from typing import Any, List, Optional, Tuple
import numpy as np
from PIL import Image
from ._central_schema import File
from .item import Item
from ._central_schema import File, Item
DEFAULT_ENCODING = "PNG"
......
......@@ -6,7 +6,6 @@ from pydantic.fields import Field
from ._central_schema import * # noqa
from .dataset import Dataset # noqa
from .item import Item
from .photo import Photo # noqa
from .utils import resolve_forward_refs
......
......@@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Any, List
import pandas as pd
if TYPE_CHECKING:
from ..data.schema.item import Item
from ..data.schema import Item
from ..pod.client import PodClient
......
......@@ -4,8 +4,7 @@ from typing import List, Optional, Union
import pytest
from pydantic import ValidationError
from pymemri.data.schema import Account, Item, Person, get_schema
from pymemri.data.schema.item import Edge
from pymemri.data.schema import Account, Edge, Item, Person, get_schema
from pymemri.pod.client import PodClient
......@@ -46,7 +45,7 @@ def test_item_init():
def test_init_with_edges():
accounts = [Account(handle="1"), Account(handle="2")]
item = MyItem(str_property="test", account_edge=accounts)
assert item.property_dict() == {"deleted": False, "str_property": "test"}
assert item.property_dict() == {"str_property": "test"}
assert len(item.account_edge) == len(item.__edges__["account_edge"]) == 2
......@@ -61,7 +60,6 @@ def test_property_dict():
"float_property": 3.0,
"bool_property": False,
"dt_property": round(dt.timestamp() * 1000),
"deleted": False,
}
assert property_dict == correct_properties
......
......@@ -3,8 +3,7 @@ import random
import pandas as pd
import pytest
from pymemri.data.schema import Account, CategoricalPrediction, Message, Person
from pymemri.data.schema.item import Edge
from pymemri.data.schema import Account, CategoricalPrediction, Edge, Message, Person
from pymemri.exporters.exporters import Query
from pymemri.pod.client import PodClient
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment