Skip to content

Commit e83b12c

Browse files
committed
serialization and deserialization tests
1 parent 8a44aaa commit e83b12c

File tree

11 files changed

+335
-34
lines changed

11 files changed

+335
-34
lines changed

labelbox/data/annotation_types/collection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ def assign_feature_schema_ids(
4040
Returns:
4141
LabelList. useful for chaining these modifying functions
4242
43-
Warning: assign_feature_schema_ids is now obsolete, you can
44-
now use names directly without having to lookup schema_ids.
43+
Note: You can now import annotations using names directly without having to lookup schema_ids
4544
"""
4645
for label in self._data:
4746
label.assign_feature_schema_ids(ontology_builder)

labelbox/data/annotation_types/label.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ def assign_feature_schema_ids(
137137
Returns:
138138
Label. useful for chaining these modifying functions
139139
140-
Warning: assign_feature_schema_ids is now obsolete, you can
141-
now use names directly without having to lookup schema_ids.
140+
Warning: You can now import annotations using names directly without having to lookup schema_ids
142141
"""
143142
tool_lookup, classification_lookup = get_feature_schema_lookup(
144143
ontology_builder)

labelbox/data/serialization/ndjson/base.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional
22
from uuid import uuid4
3-
from pydantic import BaseModel, validator, Field
3+
from pydantic import BaseModel, root_validator, validator, Field
44

55
from labelbox.utils import camel_case
66
from ...annotation_types.types import Cuid
@@ -33,20 +33,16 @@ class Config:
3333

3434

3535
class NDAnnotation(NDJsonBase):
36-
schema_id: Optional[Cuid] = None
3736
name: Optional[str] = None
37+
schema_id: Optional[Cuid] = None
3838

39-
@validator('name', pre=True, always=True)
40-
def validate_name(cls, v, values):
41-
if v is None and 'schema_id' not in values:
42-
raise ValueError(
43-
"Name and schema_id are not set. Either set name or schema_id.")
44-
45-
@validator('schema_id', pre=True, always=True)
46-
def validate_id(cls, v, values):
47-
if v is None and 'name' not in values:
39+
@root_validator()
40+
def must_set_one(cls, values):
41+
if ('schema_id' not in values or
42+
values['schema_id'] is None) and ('name' not in values or
43+
values['name'] is None):
4844
raise ValueError("Schema id or name are not set. Set either one.")
49-
return v
45+
return values
5046

5147
def dict(self, *args, **kwargs):
5248
res = super().dict(*args, **kwargs)

labelbox/data/serialization/ndjson/classification.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, Union, Optional
22

3-
from pydantic import BaseModel, Field, validator
3+
from pydantic import BaseModel, Field, root_validator
44

55
from labelbox.utils import camel_case
66
from ...annotation_types.annotation import ClassificationAnnotation, VideoClassificationAnnotation
@@ -14,19 +14,13 @@ class NDFeature(BaseModel):
1414
schema_id: Optional[Cuid] = None
1515
name: Optional[str] = None
1616

17-
@validator('name', pre=True, always=True)
18-
def validate_name(cls, v, values):
19-
if v is None and 'schema_id' not in values:
20-
raise ValueError(
21-
"Name and schema_id are not set. Either set name or schema_id.")
22-
23-
@validator('schema_id', pre=True, always=True)
24-
def validate_id(cls, v, values):
25-
if v is None and 'name' not in values:
26-
raise ValueError(
27-
"Schema ids or names are not set. Either set name or schema_id.`."
28-
)
29-
return v
17+
@root_validator()
18+
def must_set_one(cls, values):
19+
if ('schema_id' not in values or
20+
values['schema_id'] is None) and ('name' not in values or
21+
values['name'] is None):
22+
raise ValueError("Schema id or name are not set. Set either one.")
23+
return values
3024

3125
def dict(self, *args, **kwargs):
3226
res = super().dict(*args, **kwargs)
@@ -84,9 +78,10 @@ def to_common(self) -> Checklist:
8478
def from_common(cls, checklist: Checklist, name: str,
8579
feature_schema_id: Cuid) -> "NDChecklistSubclass":
8680
return cls(answer=[
87-
NDFeature(name=name, schema_id=answer.feature_schema_id)
81+
NDFeature(name=answer.name, schema_id=answer.feature_schema_id)
8882
for answer in checklist.answer
8983
],
84+
name=name,
9085
schema_id=feature_schema_id)
9186

9287
def dict(self, *args, **kwargs):
@@ -138,7 +133,7 @@ def from_common(
138133
extra: Dict[str, Any], data: Union[VideoData, TextData,
139134
ImageData]) -> "NDChecklist":
140135
return cls(answer=[
141-
NDFeature(name=name, schema_id=answer.feature_schema_id)
136+
NDFeature(name=answer.name, schema_id=answer.feature_schema_id)
142137
for answer in checklist.answer
143138
],
144139
data_row={'id': data.uid},

labelbox/schema/bulk_import_request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def validate_feature_schemas(self, valid_feature_schemas_by_id,
627627
if self.name:
628628
if self.name not in valid_feature_schemas_by_name:
629629
raise ValueError(
630-
f"name {self.name} is not valid for the provided project's ontology."
630+
f"Name {self.name} is not valid for the provided project's ontology."
631631
)
632632

633633
if self.ontology_type != valid_feature_schemas_by_name[
@@ -639,7 +639,7 @@ def validate_feature_schemas(self, valid_feature_schemas_by_id,
639639
if self.schemaId:
640640
if self.schemaId not in valid_feature_schemas_by_id:
641641
raise ValueError(
642-
f"schema id {self.schemaId} is not valid for the provided project's ontology."
642+
f"Schema id {self.schemaId} is not valid for the provided project's ontology."
643643
)
644644

645645
if self.ontology_type != valid_feature_schemas_by_id[
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"answer": { "schemaId": "ckrb1sfl8099g0y91cxbd5ftb" },
4+
"name": "classification a",
5+
"dataRow": { "id": "ckrb1sf1i1g7i0ybcdc6oc8ct" },
6+
"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673"
7+
},
8+
{
9+
"answer": [{ "schemaId": "ckrb1sfl8099e0y919v260awv" }],
10+
"name": "classification b",
11+
"dataRow": { "id": "ckrb1sf1i1g7i0ybcdc6oc8ct" },
12+
"uuid": "d009925d-91a3-4f67-abd9-753453f5a584"
13+
},
14+
{
15+
"answer": "a value",
16+
"name": "classification b",
17+
"dataRow": { "id": "ckrb1sf1i1g7i0ybcdc6oc8ct" },
18+
"uuid": "d009925d-91a3-4f67-abd9-753453f5a584"
19+
}
20+
]
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
[
2+
{
3+
"uuid": "b862c586-8614-483c-b5e6-82810f70cac0",
4+
"name": "box a",
5+
"dataRow": { "id": "ckrazctum0z8a0ybc0b0o0g0v" },
6+
"bbox": { "top": 1352, "left": 2275, "height": 350, "width": 139 }
7+
},
8+
{
9+
"uuid": "751fc725-f7b6-48ed-89b0-dd7d94d08af6",
10+
"name": "mask a",
11+
"dataRow": { "id": "ckrazctum0z8a0ybc0b0o0g0v" },
12+
"mask": {
13+
"instanceURI": "https://storage.labelbox.com/ckqcx1czn06830y61gh9v02cs%2F3e729327-f038-f66c-186e-45e921ef9717-1?Expires=1626806874672&KeyName=labelbox-assets-key-3&Signature=YsUOGKrsqmAZ68vT9BlPJOaRyLY",
14+
"colorRGB": [255, 0, 0]
15+
}
16+
},
17+
{
18+
"uuid": "43d719ac-5d7f-4aea-be00-2ebfca0900fd",
19+
"name": "polygon a",
20+
"dataRow": { "id": "ckrazctum0z8a0ybc0b0o0g0v" },
21+
"polygon": [
22+
{ "x": 1118, "y": 935 },
23+
{ "x": 1117, "y": 935 },
24+
{ "x": 1116, "y": 935 },
25+
{ "x": 1115, "y": 935 },
26+
{ "x": 1114, "y": 935 },
27+
{ "x": 1113, "y": 935 },
28+
{ "x": 1112, "y": 935 },
29+
{ "x": 1111, "y": 935 },
30+
{ "x": 1110, "y": 935 },
31+
{ "x": 1109, "y": 935 },
32+
{ "x": 1108, "y": 935 },
33+
{ "x": 1108, "y": 934 },
34+
{ "x": 1107, "y": 934 },
35+
{ "x": 1106, "y": 934 },
36+
{ "x": 1105, "y": 934 },
37+
{ "x": 1105, "y": 933 },
38+
{ "x": 1104, "y": 933 },
39+
{ "x": 1103, "y": 933 },
40+
{ "x": 1103, "y": 932 },
41+
{ "x": 1102, "y": 932 },
42+
{ "x": 1101, "y": 932 },
43+
{ "x": 1100, "y": 932 },
44+
{ "x": 1099, "y": 932 },
45+
{ "x": 1098, "y": 932 },
46+
{ "x": 1097, "y": 932 },
47+
{ "x": 1097, "y": 931 },
48+
{ "x": 1096, "y": 931 },
49+
{ "x": 1095, "y": 931 },
50+
{ "x": 1094, "y": 931 },
51+
{ "x": 1093, "y": 931 },
52+
{ "x": 1092, "y": 931 },
53+
{ "x": 1091, "y": 931 },
54+
{ "x": 1090, "y": 931 },
55+
{ "x": 1090, "y": 930 },
56+
{ "x": 1089, "y": 930 },
57+
{ "x": 1088, "y": 930 },
58+
{ "x": 1087, "y": 930 },
59+
{ "x": 1087, "y": 929 },
60+
{ "x": 1086, "y": 929 },
61+
{ "x": 1085, "y": 929 },
62+
{ "x": 1084, "y": 929 },
63+
{ "x": 1084, "y": 928 },
64+
{ "x": 1083, "y": 928 },
65+
{ "x": 1083, "y": 927 },
66+
{ "x": 1082, "y": 927 },
67+
{ "x": 1081, "y": 927 },
68+
{ "x": 1081, "y": 926 },
69+
{ "x": 1080, "y": 926 },
70+
{ "x": 1080, "y": 925 },
71+
{ "x": 1079, "y": 925 },
72+
{ "x": 1078, "y": 925 },
73+
{ "x": 1078, "y": 924 },
74+
{ "x": 1077, "y": 924 },
75+
{ "x": 1076, "y": 924 },
76+
{ "x": 1076, "y": 923 },
77+
{ "x": 1075, "y": 923 },
78+
{ "x": 1074, "y": 923 },
79+
{ "x": 1073, "y": 923 },
80+
{ "x": 1073, "y": 922 },
81+
{ "x": 1072, "y": 922 },
82+
{ "x": 1071, "y": 922 },
83+
{ "x": 1070, "y": 922 },
84+
{ "x": 1070, "y": 921 },
85+
{ "x": 1069, "y": 921 },
86+
{ "x": 1068, "y": 921 },
87+
{ "x": 1067, "y": 921 },
88+
{ "x": 1066, "y": 921 },
89+
{ "x": 1065, "y": 921 },
90+
{ "x": 1064, "y": 921 },
91+
{ "x": 1063, "y": 921 },
92+
{ "x": 1062, "y": 921 },
93+
{ "x": 1061, "y": 921 },
94+
{ "x": 1060, "y": 921 },
95+
{ "x": 1059, "y": 921 },
96+
{ "x": 1058, "y": 921 },
97+
{ "x": 1058, "y": 920 },
98+
{ "x": 1057, "y": 920 },
99+
{ "x": 1057, "y": 919 },
100+
{ "x": 1056, "y": 919 },
101+
{ "x": 1057, "y": 918 },
102+
{ "x": 1057, "y": 918 },
103+
{ "x": 1057, "y": 917 },
104+
{ "x": 1058, "y": 916 },
105+
{ "x": 1058, "y": 916 },
106+
{ "x": 1059, "y": 915 },
107+
{ "x": 1059, "y": 915 },
108+
{ "x": 1060, "y": 914 },
109+
{ "x": 1060, "y": 914 },
110+
{ "x": 1061, "y": 913 },
111+
{ "x": 1061, "y": 913 },
112+
{ "x": 1062, "y": 912 },
113+
{ "x": 1063, "y": 912 },
114+
{ "x": 1063, "y": 912 },
115+
{ "x": 1064, "y": 911 },
116+
{ "x": 1064, "y": 911 },
117+
{ "x": 1065, "y": 910 },
118+
{ "x": 1066, "y": 910 },
119+
{ "x": 1066, "y": 910 },
120+
{ "x": 1067, "y": 909 },
121+
{ "x": 1068, "y": 909 },
122+
{ "x": 1068, "y": 909 },
123+
{ "x": 1069, "y": 908 },
124+
{ "x": 1070, "y": 908 },
125+
{ "x": 1071, "y": 908 },
126+
{ "x": 1072, "y": 908 },
127+
{ "x": 1072, "y": 908 },
128+
{ "x": 1073, "y": 907 },
129+
{ "x": 1074, "y": 907 },
130+
{ "x": 1075, "y": 907 },
131+
{ "x": 1076, "y": 907 },
132+
{ "x": 1077, "y": 907 },
133+
{ "x": 1078, "y": 907 },
134+
{ "x": 1079, "y": 907 },
135+
{ "x": 1080, "y": 907 },
136+
{ "x": 1081, "y": 907 },
137+
{ "x": 1082, "y": 907 },
138+
{ "x": 1083, "y": 907 },
139+
{ "x": 1084, "y": 907 },
140+
{ "x": 1085, "y": 907 },
141+
{ "x": 1086, "y": 907 },
142+
{ "x": 1087, "y": 907 },
143+
{ "x": 1088, "y": 907 },
144+
{ "x": 1089, "y": 907 },
145+
{ "x": 1090, "y": 907 },
146+
{ "x": 1091, "y": 907 },
147+
{ "x": 1091, "y": 908 },
148+
{ "x": 1092, "y": 908 },
149+
{ "x": 1093, "y": 908 },
150+
{ "x": 1094, "y": 908 },
151+
{ "x": 1095, "y": 908 },
152+
{ "x": 1095, "y": 909 },
153+
{ "x": 1096, "y": 909 },
154+
{ "x": 1097, "y": 909 },
155+
{ "x": 1097, "y": 910 },
156+
{ "x": 1098, "y": 910 },
157+
{ "x": 1099, "y": 910 },
158+
{ "x": 1099, "y": 911 },
159+
{ "x": 1100, "y": 911 },
160+
{ "x": 1101, "y": 911 },
161+
{ "x": 1101, "y": 912 },
162+
{ "x": 1102, "y": 912 },
163+
{ "x": 1103, "y": 912 },
164+
{ "x": 1103, "y": 913 },
165+
{ "x": 1104, "y": 913 },
166+
{ "x": 1104, "y": 914 },
167+
{ "x": 1105, "y": 914 },
168+
{ "x": 1105, "y": 915 },
169+
{ "x": 1106, "y": 915 },
170+
{ "x": 1107, "y": 915 },
171+
{ "x": 1107, "y": 916 },
172+
{ "x": 1108, "y": 916 },
173+
{ "x": 1108, "y": 917 },
174+
{ "x": 1109, "y": 917 },
175+
{ "x": 1109, "y": 918 },
176+
{ "x": 1110, "y": 918 },
177+
{ "x": 1110, "y": 919 },
178+
{ "x": 1111, "y": 919 },
179+
{ "x": 1111, "y": 920 },
180+
{ "x": 1112, "y": 920 },
181+
{ "x": 1112, "y": 921 },
182+
{ "x": 1113, "y": 921 },
183+
{ "x": 1113, "y": 922 },
184+
{ "x": 1114, "y": 922 },
185+
{ "x": 1114, "y": 923 },
186+
{ "x": 1115, "y": 923 },
187+
{ "x": 1115, "y": 924 },
188+
{ "x": 1115, "y": 925 },
189+
{ "x": 1116, "y": 925 },
190+
{ "x": 1116, "y": 926 },
191+
{ "x": 1117, "y": 926 },
192+
{ "x": 1117, "y": 927 },
193+
{ "x": 1117, "y": 928 },
194+
{ "x": 1118, "y": 928 },
195+
{ "x": 1118, "y": 929 },
196+
{ "x": 1119, "y": 929 },
197+
{ "x": 1119, "y": 930 },
198+
{ "x": 1120, "y": 930 },
199+
{ "x": 1120, "y": 931 },
200+
{ "x": 1120, "y": 932 },
201+
{ "x": 1120, "y": 932 },
202+
{ "x": 1119, "y": 933 },
203+
{ "x": 1119, "y": 934 },
204+
{ "x": 1119, "y": 934 },
205+
{ "x": 1118, "y": 935 },
206+
{ "x": 1118, "y": 935 }
207+
]
208+
},
209+
{
210+
"uuid": "b98f3a45-3328-41a0-9077-373a8177ebf2",
211+
"name": "point a",
212+
"dataRow": { "id": "ckrazctum0z8a0ybc0b0o0g0v" },
213+
"point": { "x": 2122, "y": 1457 }
214+
}
215+
]

0 commit comments

Comments
 (0)