Skip to content

Commit 0b4590f

Browse files
author
Val Brodsky
committed
PR: add ndson test
1 parent 0c7be25 commit 0b4590f

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

labelbox/data/serialization/ndjson/objects.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,8 @@ class NDDocumentEntity(NDBaseObject, ConfidenceMixin):
377377
text_selections: List[DocumentTextSelection]
378378

379379
def to_common(self) -> DocumentEntity:
380-
return TextEntity(name=self.name, text_selections=self.text_selections)
381-
382-
return obj.from_common(annotation.value, subclasses, annotation.name,
383-
annotation.feature_schema_id, annotation.extra,
384-
data, **optional_kwargs)
380+
return DocumentEntity(name=self.name,
381+
text_selections=self.text_selections)
385382

386383
@classmethod
387384
def from_common(cls,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[
2+
{
3+
"uuid": "f6879f59-d2b5-49c2-aceb-d9e8dc478673",
4+
"dataRow": {
5+
"id": "ckrb1sf1i1g7i0ybcdc6oc8ct"
6+
},
7+
"name": "named_entity",
8+
"classifications": [],
9+
"textSelections": [
10+
{
11+
"groupId": "2f4336f4-a07e-4e0a-a9e1-5629b03b719b",
12+
"tokenIds": [
13+
"3f984bf3-1d61-44f5-b59a-9658a2e3440f",
14+
"3bf00b56-ff12-4e52-8cc1-08dbddb3c3b8",
15+
"6e1c3420-d4b7-4c5a-8fd6-ead43bf73d80",
16+
"87a43d32-af76-4a1d-b262-5c5f4d5ace3a",
17+
"e8606e8a-dfd9-4c49-a635-ad5c879c75d0",
18+
"67c7c19e-4654-425d-bf17-2adb8cf02c30",
19+
"149c5e80-3e07-49a7-ab2d-29ddfe6a38fa",
20+
"b0e94071-2187-461e-8e76-96c58738a52c"
21+
],
22+
"page": 1 }
23+
]
24+
}
25+
]

tests/data/serialization/ndjson/test_document.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def round_dict(data):
77
if isinstance(data, dict):
88
for key in data:
9-
if isinstance(data[key], float):
9+
if isinstance(data[key], (int, float)):
1010
data[key] = int(data[key])
1111
elif isinstance(data[key], dict):
1212
data[key] = round_dict(data[key])
@@ -28,6 +28,20 @@ def test_pdf():
2828
f.close()
2929

3030

31+
def test_pdf_document_entity():
32+
"""
33+
Tests a pdf file with bbox annotations only
34+
"""
35+
with open('tests/data/assets/ndjson/pdf_document_entity_import.json',
36+
'r') as f:
37+
data = json.load(f)
38+
res = list(NDJsonConverter.deserialize(data))
39+
res = list(NDJsonConverter.serialize(res))
40+
assert [round_dict(x) for x in res] == [round_dict(x) for x in data]
41+
42+
f.close()
43+
44+
3145
def test_pdf_with_name_only():
3246
"""
3347
Tests a pdf file with bbox annotations only

0 commit comments

Comments
 (0)