@@ -62,7 +62,9 @@ class NDLabel(BaseModel):
6262 annotations : AnnotationType
6363
6464 @classmethod
65- def from_common (cls , data : LabelCollection ) -> Generator ["NDLabel" , None , None ]:
65+ def from_common (
66+ cls , data : LabelCollection
67+ ) -> Generator ["NDLabel" , None , None ]:
6668 for label in data :
6769 yield from cls ._create_relationship_annotations (label )
6870 yield from cls ._create_non_video_annotations (label )
@@ -126,12 +128,16 @@ def _create_video_annotations(
126128 if isinstance (
127129 annot , (VideoClassificationAnnotation , VideoObjectAnnotation )
128130 ):
129- video_annotations [annot .feature_schema_id or annot .name ].append (annot )
131+ video_annotations [annot .feature_schema_id or annot .name ].append (
132+ annot
133+ )
130134 elif isinstance (annot , VideoMaskAnnotation ):
131135 yield NDObject .from_common (annotation = annot , data = label .data )
132136
133137 for annotation_group in video_annotations .values ():
134- segment_frame_ranges = cls ._get_segment_frame_ranges (annotation_group )
138+ segment_frame_ranges = cls ._get_segment_frame_ranges (
139+ annotation_group
140+ )
135141 if isinstance (annotation_group [0 ], VideoClassificationAnnotation ):
136142 annotation = annotation_group [0 ]
137143 frames_data = []
@@ -197,10 +203,12 @@ def _create_relationship_annotations(
197203 NDRelationship: Validated relationship annotations in NDJSON format
198204
199205 Raises:
200- TypeError: If source/target types violate the validation rules:
201- - Invalid source type for PDF target
202- - Non-ObjectAnnotation source for non-PDF target
203- - Non-ObjectAnnotation target
206+ TypeError: If source/target types are invalid:
207+ - Source:
208+ - For PDF target annotations (DocumentRectangle, DocumentEntity): source must be ObjectAnnotation or ClassificationAnnotation
209+ - For other target annotations: source must be ObjectAnnotation
210+ - Target:
211+ - Target must always be ObjectAnnotation
204212 """
205213 for annotation in label .annotations :
206214 if isinstance (annotation , RelationshipAnnotation ):
@@ -210,7 +218,9 @@ def _create_relationship_annotations(
210218 target = copy .copy (annotation .value .target )
211219
212220 # Check if source type is valid based on target type
213- if isinstance (target .value , (DocumentRectangle , DocumentEntity )):
221+ if isinstance (
222+ target .value , (DocumentRectangle , DocumentEntity )
223+ ):
214224 if not isinstance (
215225 source , (ObjectAnnotation , ClassificationAnnotation )
216226 ):
0 commit comments