Skip to content

Commit 7b446b3

Browse files
author
Val Brodsky
committed
Attempt to deal with typed array validation for numpy
1 parent b48d262 commit 7b446b3

File tree

1 file changed

+4
-5
lines changed
  • libs/labelbox/src/labelbox/data/annotation_types

1 file changed

+4
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import sys
22
from typing import Generic, TypeVar, Any
33

4-
from pydantic import StringConstraints
5-
64
from typing_extensions import Annotated
75
from packaging import version
86
import numpy as np
97

108
from pydantic import ValidationInfo
9+
from labelbox import pydantic_compat
1110

12-
Cuid = Annotated[str, StringConstraints(min_length=25, max_length=25)]
11+
Cuid = Annotated[str, pydantic_compat.Field(min_length=25, max_length=25)]
1312

1413
DType = TypeVar('DType')
1514
DShape = TypeVar('DShape')
@@ -22,11 +21,11 @@ def __get_validators__(cls):
2221
yield cls.validate
2322

2423
@classmethod
25-
def validate(cls, val, field: ValidationInfo):
24+
def validate(cls, val, field_info: ValidationInfo):
2625
if not isinstance(val, np.ndarray):
2726
raise TypeError(f"Expected numpy array. Found {type(val)}")
2827

29-
actual_dtype = field.sub_fields[-1].type_.__args__[0]
28+
actual_dtype = cls.model_fields[field_info.name].type_.__args__[0]
3029

3130
if val.dtype != actual_dtype:
3231
raise TypeError(

0 commit comments

Comments
 (0)