Skip to content

[PLT-1471] Remove pydantic v2 deprecate warnings #1838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 53 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0bbd7c2
Vb/fix ontology leaks plt 1379 (#1814)
vbrodsky Sep 17, 2024
51ecfea
[PTDT-2553] Added integration tests for MMC MAL/GT imports
real-mjozwiak Sep 9, 2024
8d078c8
[PTDT-2553] Added integration tests for MMC MAL/GT imports (#1795)
real-mjozwiak Sep 17, 2024
24e0766
SDK release v.5.0.0 prep (#1823)
vbrodsky Sep 17, 2024
2faf9a1
Vb/merge 5.0.0 (#1826)
vbrodsky Sep 18, 2024
2c0c677
Revert "Vb/merge 5.0.0 (#1826)" (#1827)
vbrodsky Sep 18, 2024
c089215
Removed data types besides generic data row data
Gabefire Sep 18, 2024
30819db
[PLT-1463] Removed ND deserialize from some unit test part 1 (#1804)
Gabefire Sep 16, 2024
761b1e9
[PLT-1463] Removed ND deserialize from some unit test part 2 (#1815)
Gabefire Sep 16, 2024
379171a
[PLT-1274] Vb/deprecate bulkimportrequest plt 1274 (#1821)
vbrodsky Sep 17, 2024
5e87f4e
[PLT-1463] Remove deserialize completely (#1818)
Gabefire Sep 18, 2024
5fc6ff3
[PLT-1488] Removed coco (#1820)
Gabefire Sep 18, 2024
9cf28a1
Fixed video
Gabefire Sep 18, 2024
7fc10bb
Removed data type test
Gabefire Sep 18, 2024
8051d50
Merge branch 'solve_rebase_v6' into v6
Gabefire Sep 18, 2024
0b810fb
Made fix
Gabefire Sep 19, 2024
f8b8fa3
Fix list of labels
Gabefire Sep 19, 2024
556a5db
Merge branch 'v6' into gu/remove_data_types
Gabefire Sep 19, 2024
aa551e1
Merge branch 'gu/remove_data_types' of github.com:Labelbox/labelbox-p…
Gabefire Sep 19, 2024
2329324
Removed add url
Gabefire Sep 19, 2024
4457f25
Removed rest of tests
Gabefire Sep 19, 2024
f5b6c7d
Fix tests
Gabefire Sep 19, 2024
ce60b24
Finish PR
Gabefire Sep 19, 2024
12aa8c5
Added back in tile data since some of its parameters are required
Gabefire Sep 23, 2024
f124e9d
Merge branch 'v6' of github.com:Labelbox/labelbox-python into v6
Gabefire Sep 23, 2024
b614ced
Removed data types besides generic data row data
Gabefire Sep 18, 2024
e31d118
Fixed video
Gabefire Sep 18, 2024
1a8189a
Removed data type test
Gabefire Sep 18, 2024
62f5fbd
Made fix
Gabefire Sep 19, 2024
6c11e74
Fix list of labels
Gabefire Sep 19, 2024
1ef53cc
Removed add url
Gabefire Sep 19, 2024
159e227
Removed rest of tests
Gabefire Sep 19, 2024
5f625c8
Fix tests
Gabefire Sep 19, 2024
90c1a19
Finish PR
Gabefire Sep 19, 2024
f91a229
Added back in tile data since some of its parameters are required
Gabefire Sep 23, 2024
709ca61
Merge branch 'gu/remove_data_types' of github.com:Labelbox/labelbox-p…
Gabefire Sep 23, 2024
fdabc94
Added tile back to __init__.py
Gabefire Sep 23, 2024
5bb3c97
Fixed import
Gabefire Sep 23, 2024
4888346
Removed some data tests
Gabefire Sep 23, 2024
c32bd71
Removed videoData
Gabefire Sep 23, 2024
1c50842
Fix exception type for labeling service test (#1835)
vbrodsky Sep 23, 2024
075f6c0
Merge branch 'v6' of github.com:Labelbox/labelbox-python into v6
Gabefire Sep 23, 2024
dd5ccdd
Merge branch 'v6' into gu/cut_down_warnings
Gabefire Sep 23, 2024
3c7e72c
Removed some warnings
Gabefire Sep 23, 2024
a824f55
Merge remote-tracking branch 'origin' into gu/cut_down_warnings
Gabefire Sep 23, 2024
3dd9911
Fix merge conflicts
Gabefire Sep 23, 2024
4be8069
Add client back in
Gabefire Sep 23, 2024
321cdaf
Remove test_labeling_service changes
Gabefire Sep 23, 2024
673f367
Flip string remover to before validation
Gabefire Sep 23, 2024
d3ee85a
removed deprecated timezone from tests
Gabefire Sep 23, 2024
dd531ee
Fixed labeling service
Gabefire Sep 24, 2024
fb60c88
Swapped to Any
Gabefire Sep 24, 2024
8782117
Revert some changes
Gabefire Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions libs/labelbox/src/labelbox/data/annotation_types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
from packaging import version
import numpy as np

from pydantic import StringConstraints, Field
from pydantic import StringConstraints, Field, ConfigDict
from pydantic_core import core_schema

DType = TypeVar("DType")
DShape = TypeVar("DShape")


class _TypedArray(np.ndarray, Generic[DType, DShape]):
@classmethod
def __get_validators__(cls):
yield cls.validate
def __get_pydantic_core_schema__(
Copy link
Collaborator Author

@Gabefire Gabefire Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a story to simplify this class

cls, _source_type: type, _model: type
) -> core_schema.CoreSchema:
return core_schema.no_info_plain_validator_function(cls.validate)

@classmethod
def validate(cls, val, field: Field):
def validate(cls, val):
if not isinstance(val, np.ndarray):
raise TypeError(f"Expected numpy array. Found {type(val)}")
return val
Expand Down
9 changes: 8 additions & 1 deletion libs/labelbox/src/labelbox/schema/data_row_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
conlist,
ConfigDict,
model_serializer,
BeforeValidator,
)

from labelbox.schema.ontology import SchemaId
Expand All @@ -36,6 +37,12 @@
format_iso_from_string,
)

Name = Annotated[
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good

str,
BeforeValidator(lambda x: str.strip(str(x))),
Field(min_length=1, max_length=100),
]


class DataRowMetadataKind(Enum):
number = "CustomMetadataNumber"
Expand All @@ -49,7 +56,7 @@ class DataRowMetadataKind(Enum):
# Metadata schema
class DataRowMetadataSchema(BaseModel):
uid: SchemaId
name: str = Field(strip_whitespace=True, min_length=1, max_length=100)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strip_whitespace is depercated in pydantic V2 and gives warnings to users

name: Name
reserved: bool
kind: DataRowMetadataKind
options: Optional[List["DataRowMetadataSchema"]] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Any, Dict, List, Optional, Union

from lbox.exceptions import ResourceNotFoundError
from pydantic import BaseModel, Field, model_validator
from pydantic import BaseModel, Field, model_validator, model_serializer

from labelbox.pagination import PaginatedCollection
from labelbox.schema.labeling_service_status import LabelingServiceStatus
Expand Down Expand Up @@ -50,7 +50,7 @@ class LabelingServiceDashboard(_CamelCaseMixin):
Represent labeling service data for a project

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.
In the current implementation a task reprsents a single data row. However tasks only exists when a labeler start labeling a data row.
In the current implementation a task represents a single data row. However tasks only exists when a labeler start labeling a data row.
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.

Attributes:
Expand Down Expand Up @@ -221,8 +221,9 @@ def convert_boost_data(cls, data):

return data

def dict(self, *args, **kwargs):
row = super().dict(*args, **kwargs)
@model_serializer()
def ser_model(self):
row = self
row.pop("client")
row["service_type"] = self.service_type
return row
5 changes: 2 additions & 3 deletions libs/labelbox/src/labelbox/schema/search_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from typing_extensions import Annotated

from pydantic import BaseModel, Field, field_validator
from pydantic import BaseModel, Field, field_validator, ConfigDict
from labelbox.schema.labeling_service_status import LabelingServiceStatus
from labelbox.utils import format_iso_datetime

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

class Config:
use_enum_values = True
model_config = ConfigDict(use_enum_values=True)


class OperationTypeEnum(Enum):
Expand Down
6 changes: 3 additions & 3 deletions libs/labelbox/tests/integration/test_data_rows.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
import uuid
from datetime import datetime
from datetime import datetime, timezone
from tempfile import NamedTemporaryFile
from unittest.mock import patch

Expand Down Expand Up @@ -95,7 +95,7 @@ def tile_content():

def make_metadata_fields():
msg = "A message"
time = datetime.utcnow()
time = datetime.now(timezone.utc)

fields = [
DataRowMetadataField(schema_id=SPLIT_SCHEMA_ID, value=TEST_SPLIT_ID),
Expand All @@ -107,7 +107,7 @@ def make_metadata_fields():

def make_metadata_fields_dict():
msg = "A message"
time = datetime.utcnow()
time = datetime.now(timezone.utc)

fields = [
{"schema_id": SPLIT_SCHEMA_ID, "value": TEST_SPLIT_ID},
Expand Down
Loading