Skip to content

Commit 00e6492

Browse files
author
Val Brodsky
committed
Deal with custom field validation
1 parent 3e299e9 commit 00e6492

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

libs/labelbox/src/labelbox/data/annotation_types/types.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from packaging import version
88
import numpy as np
99

10-
from pydantic import Field
10+
from pydantic import ValidationInfo
1111

1212
Cuid = Annotated[str, StringConstraints(min_length=25, max_length=25)]
1313

@@ -22,14 +22,11 @@ def __get_validators__(cls):
2222
yield cls.validate
2323

2424
@classmethod
25-
def validate(cls, val, field: pydantic_compat.ModelField):
25+
def validate(cls, val, field: ValidationInfo):
2626
if not isinstance(val, np.ndarray):
2727
raise TypeError(f"Expected numpy array. Found {type(val)}")
2828

29-
if sys.version_info.minor > 6:
30-
actual_dtype = field.sub_fields[-1].type_.__args__[0]
31-
else:
32-
actual_dtype = field.sub_fields[-1].type_.__values__[0]
29+
actual_dtype = field.sub_fields[-1].type_.__args__[0]
3330

3431
if val.dtype != actual_dtype:
3532
raise TypeError(

libs/labelbox/src/labelbox/schema/data_row_metadata.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ class DataRowMetadataSchema(BaseModel):
4040

4141
DataRowMetadataSchema.update_forward_refs()
4242

43-
Embedding: Type[List[float]] = Annotated[List[float], Field(
44-
min_items=128,
45-
max_items=128)]
43+
Embedding: Type[List[float]] = Annotated[List[float],
44+
Field(min_items=128, max_items=128)]
4645
String: Type[str] = Annotated[List[str], Field(max_length=4096)]
4746

4847

0 commit comments

Comments
 (0)