Skip to content

Commit 914df3d

Browse files
author
Val Brodsky
committed
Dealing with pydantic deserialization of subclasses
1 parent 4e35ffc commit 914df3d

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

labelbox/data/annotation_types/annotation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from .classification import Checklist, Dropdown, Radio, Text
77
from .feature import FeatureSchema
88
from .geometry import Geometry, Rectangle, Point
9-
from .ner import DocumentEntity, TextEntity
9+
from .ner import DocumentEntity, TextEntity, ConversationEntity
1010

1111

1212
class BaseAnnotation(FeatureSchema, abc.ABC):
@@ -51,7 +51,7 @@ class ObjectAnnotation(BaseAnnotation, ConfidenceMixin):
5151
classifications (Optional[List[ClassificationAnnotation]]): Optional sub classification of the annotation
5252
extra (Dict[str, Any])
5353
"""
54-
value: Union[Type[TextEntity], DocumentEntity, Geometry]
54+
value: Union[TextEntity, ConversationEntity, DocumentEntity, Geometry]
5555
classifications: List[ClassificationAnnotation] = []
5656

5757

labelbox/data/serialization/ndjson/label.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ...annotation_types.collection import LabelCollection, LabelGenerator
1111
from ...annotation_types.data import ImageData, TextData, VideoData
1212
from ...annotation_types.label import Label
13-
from ...annotation_types.ner import TextEntity
13+
from ...annotation_types.ner import TextEntity, ConversationEntity
1414
from ...annotation_types.classification import Dropdown
1515
from ...annotation_types.metrics import ScalarMetric, ConfusionMatrixMetric
1616

@@ -52,7 +52,6 @@ def _generate_annotations(
5252
annots = []
5353
data_row = annotations[0].data_row
5454
for annotation in annotations:
55-
5655
if isinstance(annotation, NDSegments):
5756
annots.extend(
5857
NDSegments.to_common(annotation, annotation.name,
@@ -72,7 +71,7 @@ def _generate_annotations(
7271

7372
def _infer_media_type(
7473
self, data_row: DataRow,
75-
annotations: List[Union[TextEntity, VideoClassificationAnnotation,
74+
annotations: List[Union[TextEntity, ConversationEntity, VideoClassificationAnnotation,
7675
VideoObjectAnnotation, ObjectAnnotation,
7776
ClassificationAnnotation, ScalarMetric,
7877
ConfusionMatrixMetric]]
@@ -82,7 +81,7 @@ def _infer_media_type(
8281

8382
types = {type(annotation) for annotation in annotations}
8483
data = ImageData
85-
if TextEntity in types:
84+
if TextEntity in types or ConversationEntity:
8685
data = TextData
8786
elif VideoClassificationAnnotation in types or VideoObjectAnnotation in types:
8887
data = VideoData

labelbox/data/serialization/ndjson/objects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ def lookup_object(
500500
return result
501501

502502

503+
NERTextType = Union[NDConversationEntity, NDTextEntity]
503504
NDObjectType = Union[NDLine, NDPolygon, NDPoint, NDRectangle, NDMask,
504-
Type[NDTextEntity], NDDocumentEntity]
505+
NERTextType, NDDocumentEntity]
505506

506507
NDFrameObjectType = NDFrameRectangle, NDFramePoint, NDFrameLine

tests/data/serialization/ndjson/test_text_entity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
def test_text_entity_import(filename: str):
1313
with open(filename, 'r') as file:
1414
data = json.load(file)
15+
1516
res = list(NDJsonConverter.deserialize(data))
1617
res = list(NDJsonConverter.serialize(res))
1718
assert res == data

0 commit comments

Comments
 (0)