Skip to content

Commit e362281

Browse files
GabefireVal Brodsky
authored andcommitted
[PLT-1471] Remove pydantic v2 deprecate warnings (#1838)
1 parent 250e063 commit e362281

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55
from packaging import version
66
import numpy as np
77

8-
from pydantic import StringConstraints, Field
8+
from pydantic import StringConstraints, Field, ConfigDict
9+
from pydantic_core import core_schema
910

1011
DType = TypeVar("DType")
1112
DShape = TypeVar("DShape")
1213

1314

1415
class _TypedArray(np.ndarray, Generic[DType, DShape]):
1516
@classmethod
16-
def __get_validators__(cls):
17-
yield cls.validate
17+
def __get_pydantic_core_schema__(
18+
cls, _source_type: type, _model: type
19+
) -> core_schema.CoreSchema:
20+
return core_schema.no_info_plain_validator_function(cls.validate)
1821

1922
@classmethod
20-
def validate(cls, val, field: Field):
23+
def validate(cls, val):
2124
if not isinstance(val, np.ndarray):
2225
raise TypeError(f"Expected numpy array. Found {type(val)}")
2326
return val

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
conlist,
2828
ConfigDict,
2929
model_serializer,
30+
BeforeValidator,
3031
)
3132

3233
from labelbox.schema.ontology import SchemaId
@@ -36,6 +37,12 @@
3637
format_iso_from_string,
3738
)
3839

40+
Name = Annotated[
41+
str,
42+
BeforeValidator(lambda x: str.strip(str(x))),
43+
Field(min_length=1, max_length=100),
44+
]
45+
3946

4047
class DataRowMetadataKind(Enum):
4148
number = "CustomMetadataNumber"
@@ -49,7 +56,7 @@ class DataRowMetadataKind(Enum):
4956
# Metadata schema
5057
class DataRowMetadataSchema(BaseModel):
5158
uid: SchemaId
52-
name: str = Field(strip_whitespace=True, min_length=1, max_length=100)
59+
name: Name
5360
reserved: bool
5461
kind: DataRowMetadataKind
5562
options: Optional[List["DataRowMetadataSchema"]] = None

libs/labelbox/src/labelbox/schema/labeling_service_dashboard.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any, Dict, List, Optional, Union
44

55
from lbox.exceptions import ResourceNotFoundError
6-
from pydantic import BaseModel, Field, model_validator
6+
from pydantic import BaseModel, Field, model_validator, model_serializer
77

88
from labelbox.pagination import PaginatedCollection
99
from labelbox.schema.labeling_service_status import LabelingServiceStatus
@@ -50,7 +50,7 @@ class LabelingServiceDashboard(_CamelCaseMixin):
5050
Represent labeling service data for a project
5151
5252
NOTE on tasks vs data rows. A task is a unit of work that is assigned to a user. A data row is a unit of data that needs to be labeled.
53-
In the current implementation a task reprsents a single data row. However tasks only exists when a labeler start labeling a data row.
53+
In the current implementation a task represents a single data row. However tasks only exists when a labeler start labeling a data row.
5454
So if a data row is not labeled, it will not have a task associated with it. Therefore the number of tasks can be less than the number of data rows.
5555
5656
Attributes:
@@ -221,8 +221,9 @@ def convert_boost_data(cls, data):
221221

222222
return data
223223

224-
def dict(self, *args, **kwargs):
225-
row = super().dict(*args, **kwargs)
224+
@model_serializer()
225+
def ser_model(self):
226+
row = self
226227
row.pop("client")
227228
row["service_type"] = self.service_type
228229
return row

libs/labelbox/src/labelbox/schema/search_filters.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from typing_extensions import Annotated
77

8-
from pydantic import BaseModel, Field, field_validator
8+
from pydantic import BaseModel, Field, field_validator, ConfigDict
99
from labelbox.schema.labeling_service_status import LabelingServiceStatus
1010
from labelbox.utils import format_iso_datetime
1111

@@ -15,8 +15,7 @@ class BaseSearchFilter(BaseModel):
1515
Shared code for all search filters
1616
"""
1717

18-
class Config:
19-
use_enum_values = True
18+
model_config = ConfigDict(use_enum_values=True)
2019

2120

2221
class OperationTypeEnum(Enum):

0 commit comments

Comments
 (0)