Skip to content

Commit c077327

Browse files
committed
fix semantic conflict and add more tests
1 parent 2ba0762 commit c077327

File tree

6 files changed

+148
-3
lines changed

6 files changed

+148
-3
lines changed

labelbox/data/serialization/ndjson/objects.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ def from_common(cls, point: Point,
6565
class NDFramePoint(VideoSupported):
6666
point: _Point
6767

68-
def to_common(self, feature_schema_id: Cuid) -> VideoObjectAnnotation:
68+
def to_common(self, name: str,
69+
feature_schema_id: Cuid) -> VideoObjectAnnotation:
6970
return VideoObjectAnnotation(frame=self.frame,
7071
keyframe=True,
72+
name=name,
7173
feature_schema_id=feature_schema_id,
7274
value=Point(x=self.point.x,
7375
y=self.point.y))
@@ -102,10 +104,12 @@ def from_common(cls, line: Line,
102104
class NDFrameLine(VideoSupported):
103105
line: List[_Point]
104106

105-
def to_common(self, feature_schema_id: Cuid) -> VideoObjectAnnotation:
107+
def to_common(self, name: str,
108+
feature_schema_id: Cuid) -> VideoObjectAnnotation:
106109
return VideoObjectAnnotation(
107110
frame=self.frame,
108111
keyframe=True,
112+
name=name,
109113
feature_schema_id=feature_schema_id,
110114
value=Line(points=[Point(x=pt.x, y=pt.y) for pt in self.line]))
111115

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
[{"answer": {"schemaId": "ckrb1sfl8099g0y91cxbd5ftb"}, "schemaId": "ckrb1sfjx099a0y914hl319ie", "dataRow": {"id": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, "uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673"}, {"answer": [{"schemaId": "ckrb1sfl8099e0y919v260awv"}], "schemaId": "ckrb1sfkn099c0y910wbo0p1a", "dataRow": {"id": "ckrb1sf1i1g7i0ybcdc6oc8ct"}, "uuid": "d009925d-91a3-4f67-abd9-753453f5a584"}]
1+
[
2+
{
3+
"answer": { "schemaId": "ckrb1sfl8099g0y91cxbd5ftb" },
4+
"schemaId": "ckrb1sfjx099a0y914hl319ie",
5+
"dataRow": { "id": "ckrb1sf1i1g7i0ybcdc6oc8ct" },
6+
"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673"
7+
},
8+
{
9+
"answer": [{ "schemaId": "ckrb1sfl8099e0y919v260awv" }],
10+
"schemaId": "ckrb1sfkn099c0y910wbo0p1a",
11+
"dataRow": { "id": "ckrb1sf1i1g7i0ybcdc6oc8ct" },
12+
"uuid": "d009925d-91a3-4f67-abd9-753453f5a584"
13+
}
14+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"answer": { "name": "answer a" },
4+
"name": "question 1",
5+
"dataRow": { "id": "ckrb1sf1i1g7i0ybcdc6oc8ct" },
6+
"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673"
7+
},
8+
{
9+
"answer": [{ "name": "answer b" }],
10+
"name": "question 2",
11+
"dataRow": { "id": "ckrb1sf1i1g7i0ybcdc6oc8ct" },
12+
"uuid": "d009925d-91a3-4f67-abd9-753453f5a584"
13+
}
14+
]
15+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
[
2+
{
3+
"answer": {"name": "answer 1"},
4+
"name": "question 1",
5+
"dataRow": {"id": "ckrb1sf1i1g7i0ybcdc6oc8ct"},
6+
"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673",
7+
"frames": [{"start": 30, "end": 35}, {"start": 50, "end": 51}]
8+
},
9+
{
10+
"answer": [{"name": "answer 2"}],
11+
"name": "question 2",
12+
"dataRow": {"id": "ckrb1sf1i1g7i0ybcdc6oc8ct"},
13+
"uuid": "d009925d-91a3-4f67-abd9-753453f5a584",
14+
"frames": [{"start": 0, "end": 5}]
15+
},
16+
{
17+
"answer": "a value",
18+
"name": "question 3",
19+
"dataRow": {"id": "ckrb1sf1i1g7i0ybcdc6oc8ct"},
20+
"uuid": "d009925d-91a3-4f67-abd9-753453f5a584"
21+
},
22+
{
23+
"classifications": [],
24+
"name": "segment 1",
25+
"dataRow": {"id": "ckrb1sf1i1g7i0ybcdc6oc8ct"},
26+
"uuid": "6f7c835a-0139-4896-b73f-66a6baa89e94",
27+
"segments": [
28+
{
29+
"keyframes": [
30+
{
31+
"frame": 1,
32+
"line": [{"x": 10.0, "y": 10.0}, {"x": 100.0, "y": 100.0}, {"x": 50.0, "y": 30.0}]
33+
}
34+
]
35+
},
36+
{
37+
"keyframes": [
38+
{
39+
"frame": 5,
40+
"line": [{"x": 100.0, "y": 10.0}, {"x": 50.0, "y": 100.0}, {"x": 50.0, "y": 30.0}]
41+
}
42+
]
43+
}
44+
]
45+
},
46+
{
47+
"classifications": [],
48+
"name": "segment 2",
49+
"dataRow": {"id": "ckrb1sf1i1g7i0ybcdc6oc8ct"},
50+
"uuid": "f963be22-227b-4efe-9be4-2738ed822216",
51+
"segments": [
52+
{
53+
"keyframes": [
54+
{
55+
"frame": 1,
56+
"point": {"x": 10.0, "y": 10.0}
57+
}
58+
]
59+
},
60+
{
61+
"keyframes": [
62+
{
63+
"frame": 5,
64+
"point": {"x": 50.0, "y": 50.0}
65+
}
66+
]
67+
}
68+
]
69+
},
70+
{
71+
"classifications": [],
72+
"name": "segment 3",
73+
"dataRow": {"id": "ckrb1sf1i1g7i0ybcdc6oc8ct"},
74+
"uuid": "13b2ee0e-2355-4336-8b83-d74d09e3b1e7",
75+
"segments": [
76+
{
77+
"keyframes": [
78+
{
79+
"frame": 1,
80+
"bbox": {"top": 10.0, "left": 5.0, "height": 100.0, "width": 150.0}
81+
}
82+
]
83+
},
84+
{
85+
"keyframes": [
86+
{
87+
"frame": 5,
88+
"bbox": {"top": 300.0, "left": 200.0, "height": 400.0, "width": 150.0}
89+
}
90+
]
91+
}
92+
]
93+
}
94+
]

tests/data/serialization/ndjson/test_text.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,12 @@ def test_text():
99
res = NDJsonConverter.deserialize(data).as_list()
1010
res = list(NDJsonConverter.serialize(res))
1111
assert res == data
12+
13+
14+
def test_text_name_only():
15+
with open('tests/data/assets/ndjson/text_import_name_only.json',
16+
'r') as file:
17+
data = json.load(file)
18+
res = NDJsonConverter.deserialize(data).as_list()
19+
res = list(NDJsonConverter.serialize(res))
20+
assert res == data

tests/data/serialization/ndjson/test_video.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,13 @@ def test_video():
1010
res = NDJsonConverter.deserialize(data).as_list()
1111
res = list(NDJsonConverter.serialize(res))
1212
assert res == [data[2], data[0], data[1], data[3], data[4], data[5]]
13+
14+
15+
def test_video_name_only():
16+
with open('tests/data/assets/ndjson/video_import_name_only.json',
17+
'r') as file:
18+
data = json.load(file)
19+
20+
res = NDJsonConverter.deserialize(data).as_list()
21+
res = list(NDJsonConverter.serialize(res))
22+
assert res == [data[2], data[0], data[1], data[3], data[4], data[5]]

0 commit comments

Comments
 (0)