Skip to content

Commit 5c8d9ef

Browse files
author
Val Brodsky
committed
Lint updates
1 parent 9434cef commit 5c8d9ef

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

libs/labelbox/src/labelbox/data/serialization/ndjson/classification.py

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ class NDAnswer(ConfidenceMixin, CustomMetricsMixin):
1919
name: Optional[str] = None
2020
schema_id: Optional[Cuid] = None
2121
classifications: Optional[List['NDSubclassificationType']] = None
22-
model_config = ConfigDict(populate_by_name = True, alias_generator = to_camel)
22+
model_config = ConfigDict(populate_by_name=True, alias_generator=to_camel)
2323

2424
@model_validator(mode="after")
2525
def must_set_one(self):
26-
if (not hasattr(self, "schema_id") or self.schema_id is None) and (not hasattr(self, "name") or self.name is None):
26+
if (not hasattr(self, "schema_id") or self.schema_id
27+
is None) and (not hasattr(self, "name") or self.name is None):
2728
raise ValueError("Schema id or name are not set. Set either one.")
2829
return self
2930

@@ -103,7 +104,10 @@ def from_common(cls, checklist: Checklist, name: str,
103104
NDAnswer(name=answer.name,
104105
schema_id=answer.feature_schema_id,
105106
confidence=answer.confidence,
106-
classifications=[NDSubclassification.from_common(annot) for annot in answer.classifications] if answer.classifications else None,
107+
classifications=[
108+
NDSubclassification.from_common(annot)
109+
for annot in answer.classifications
110+
] if answer.classifications else None,
107111
custom_metrics=answer.custom_metrics)
108112
for answer in checklist.answer
109113
],
@@ -153,8 +157,8 @@ class NDPromptTextSubclass(NDAnswer):
153157

154158
def to_common(self) -> PromptText:
155159
return PromptText(answer=self.answer,
156-
confidence=self.confidence,
157-
custom_metrics=self.custom_metrics)
160+
confidence=self.confidence,
161+
custom_metrics=self.custom_metrics)
158162

159163
@classmethod
160164
def from_common(cls, prompt_text: PromptText, name: str,
@@ -195,7 +199,8 @@ def from_common(cls,
195199
)
196200

197201

198-
class NDChecklist(NDAnnotation, NDChecklistSubclass, VideoSupported, _SubclassRegistryBase):
202+
class NDChecklist(NDAnnotation, NDChecklistSubclass, VideoSupported,
203+
_SubclassRegistryBase):
199204

200205
@model_serializer(mode="wrap")
201206
def serialize_model(self, handler):
@@ -238,7 +243,8 @@ def from_common(
238243
confidence=confidence)
239244

240245

241-
class NDRadio(NDAnnotation, NDRadioSubclass, VideoSupported, _SubclassRegistryBase):
246+
class NDRadio(NDAnnotation, NDRadioSubclass, VideoSupported,
247+
_SubclassRegistryBase):
242248

243249
@classmethod
244250
def from_common(
@@ -267,35 +273,32 @@ def from_common(
267273
frames=extra.get('frames'),
268274
message_id=message_id,
269275
confidence=confidence)
270-
276+
271277
@model_serializer(mode="wrap")
272278
def serialize_model(self, handler):
273279
res = handler(self)
274280
if "classifications" in res and res["classifications"] == []:
275281
del res["classifications"]
276282
return res
277-
278-
283+
284+
279285
class NDPromptText(NDAnnotation, NDPromptTextSubclass, _SubclassRegistryBase):
280-
286+
281287
@classmethod
282-
def from_common(
283-
cls,
284-
uuid: str,
285-
text: PromptText,
286-
name,
287-
data: Dict,
288-
feature_schema_id: Cuid,
289-
confidence: Optional[float] = None
290-
) -> "NDPromptText":
291-
return cls(
292-
answer=text.answer,
293-
data_row=DataRow(id=data.uid, global_key=data.global_key),
294-
name=name,
295-
schema_id=feature_schema_id,
296-
uuid=uuid,
297-
confidence=text.confidence,
298-
custom_metrics=text.custom_metrics)
288+
def from_common(cls,
289+
uuid: str,
290+
text: PromptText,
291+
name,
292+
data: Dict,
293+
feature_schema_id: Cuid,
294+
confidence: Optional[float] = None) -> "NDPromptText":
295+
return cls(answer=text.answer,
296+
data_row=DataRow(id=data.uid, global_key=data.global_key),
297+
name=name,
298+
schema_id=feature_schema_id,
299+
uuid=uuid,
300+
confidence=text.confidence,
301+
custom_metrics=text.custom_metrics)
299302

300303

301304
class NDSubclassification:
@@ -351,7 +354,8 @@ def to_common(
351354
for frame in annotation.frames:
352355
for idx in range(frame.start, frame.end + 1, 1):
353356
results.append(
354-
VideoClassificationAnnotation(frame=idx, **common.model_dump(exclude_none=True)))
357+
VideoClassificationAnnotation(
358+
frame=idx, **common.model_dump(exclude_none=True)))
355359
return results
356360

357361
@classmethod
@@ -383,6 +387,7 @@ def lookup_classification(
383387
Radio: NDRadio
384388
}.get(type(annotation.value))
385389

390+
386391
class NDPromptClassification:
387392

388393
@staticmethod
@@ -405,8 +410,7 @@ def from_common(
405410
data: Union[VideoData, TextData, ImageData]
406411
) -> Union[NDTextSubclass, NDChecklistSubclass, NDRadioSubclass]:
407412
return NDPromptText.from_common(str(annotation._uuid), annotation.value,
408-
annotation.name,
409-
data,
413+
annotation.name, data,
410414
annotation.feature_schema_id,
411415
annotation.confidence)
412416

@@ -428,4 +432,4 @@ def from_common(
428432
# Make sure to keep NDChecklist prior to NDRadio in the list,
429433
# otherwise list of answers gets parsed by NDRadio whereas NDChecklist must be used
430434
NDClassificationType = Union[NDChecklist, NDRadio, NDText]
431-
NDPromptClassificationType = Union[NDPromptText]
435+
NDPromptClassificationType = Union[NDPromptText]

0 commit comments

Comments
 (0)