Skip to content
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

[BUGFIX] [TESTS] Remove custom isoformat parsing and let pydantic do the work #5752

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 0 additions & 10 deletions argilla/src/argilla/_api/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime
from typing import Generic, TYPE_CHECKING, TypeVar
from uuid import UUID

from argilla._helpers import LoggingMixin


if TYPE_CHECKING:
from httpx import Client


__all__ = ["ResourceAPI"]

T = TypeVar("T")
Expand Down Expand Up @@ -51,10 +48,3 @@ def delete(self, id: UUID) -> None:

def update(self, resource: T) -> T:
return resource

####################
# Utility methods #
####################

def _date_from_iso_format(self, date: str) -> datetime:
return datetime.fromisoformat(date)
2 changes: 0 additions & 2 deletions argilla/src/argilla/_api/_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ def name_exists(self, name: str, workspace_id: UUID) -> bool:
####################

def _model_from_json(self, response_json: Dict) -> "DatasetModel":
response_json["inserted_at"] = self._date_from_iso_format(date=response_json["inserted_at"])
response_json["updated_at"] = self._date_from_iso_format(date=response_json["updated_at"])
return DatasetModel(**response_json)

def _model_from_jsons(self, response_jsons: List[Dict]) -> List["DatasetModel"]:
Expand Down
2 changes: 0 additions & 2 deletions argilla/src/argilla/_api/_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ def list(self, dataset_id: UUID) -> List[FieldModel]:
####################

def _model_from_json(self, response_json: Dict) -> FieldModel:
response_json["inserted_at"] = self._date_from_iso_format(date=response_json["inserted_at"])
response_json["updated_at"] = self._date_from_iso_format(date=response_json["updated_at"])
return FieldModel(**response_json)

def _model_from_jsons(self, response_jsons: List[Dict]) -> List[FieldModel]:
Expand Down
2 changes: 0 additions & 2 deletions argilla/src/argilla/_api/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ def list(self, dataset_id: UUID) -> List[MetadataFieldModel]:
####################

def _model_from_json(self, response_json: Dict) -> MetadataFieldModel:
response_json["inserted_at"] = self._date_from_iso_format(date=response_json["inserted_at"])
response_json["updated_at"] = self._date_from_iso_format(date=response_json["updated_at"])
return MetadataFieldModel(**response_json)

def _model_from_jsons(self, response_jsons: List[Dict]) -> List[MetadataFieldModel]:
Expand Down
2 changes: 0 additions & 2 deletions argilla/src/argilla/_api/_questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ def list(self, dataset_id: UUID) -> List[QuestionModel]:
####################

def _model_from_json(self, response_json: Dict) -> QuestionModel:
response_json["inserted_at"] = self._date_from_iso_format(date=response_json["inserted_at"])
response_json["updated_at"] = self._date_from_iso_format(date=response_json["updated_at"])
return QuestionModel(**response_json)

def _model_from_jsons(self, response_jsons: List[Dict]) -> List[QuestionModel]:
Expand Down
2 changes: 0 additions & 2 deletions argilla/src/argilla/_api/_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,6 @@ def create_record_responses(self, record: RecordModel) -> None:
####################

def _model_from_json(self, response_json: Dict) -> RecordModel:
response_json["inserted_at"] = self._date_from_iso_format(date=response_json["inserted_at"])
response_json["updated_at"] = self._date_from_iso_format(date=response_json["updated_at"])
if "vectors" in response_json:
response_json["vectors"] = [
{"name": key, "vector_values": value} for key, value in response_json["vectors"].items()
Expand Down
2 changes: 0 additions & 2 deletions argilla/src/argilla/_api/_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ def delete_from_workspace(self, workspace_id: UUID, user_id: UUID) -> "UserModel
####################

def _model_from_json(self, response_json) -> UserModel:
response_json["inserted_at"] = self._date_from_iso_format(date=response_json["inserted_at"])
response_json["updated_at"] = self._date_from_iso_format(date=response_json["updated_at"])
return UserModel(**response_json)

def _model_from_jsons(self, response_jsons) -> List[UserModel]:
Expand Down
2 changes: 0 additions & 2 deletions argilla/src/argilla/_api/_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ def list(self, dataset_id: UUID) -> List[VectorFieldModel]:
####################

def _model_from_json(self, response_json: Dict) -> VectorFieldModel:
response_json["inserted_at"] = self._date_from_iso_format(date=response_json["inserted_at"])
response_json["updated_at"] = self._date_from_iso_format(date=response_json["updated_at"])
return VectorFieldModel(**response_json)

def _model_from_jsons(self, response_jsons: List[Dict]) -> List[VectorFieldModel]:
Expand Down
4 changes: 2 additions & 2 deletions argilla/src/argilla/_api/_workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def _model_from_json(self, json_workspace: Dict) -> WorkspaceModel:
return WorkspaceModel(
id=UUID(json_workspace["id"]),
name=json_workspace["name"],
inserted_at=self._date_from_iso_format(date=json_workspace["inserted_at"]),
updated_at=self._date_from_iso_format(date=json_workspace["updated_at"]),
inserted_at=json_workspace["inserted_at"],
updated_at=json_workspace["updated_at"],
)

def _model_from_jsons(self, json_workspaces: List[Dict]) -> List[WorkspaceModel]:
Expand Down
14 changes: 14 additions & 0 deletions argilla/tests/unit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024-present, Argilla, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

35 changes: 35 additions & 0 deletions argilla/tests/unit/models/test_workspace_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2024-present, Argilla, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime

from dateutil import tz

from argilla._models import WorkspaceModel


class TestWorkspaceModels:
def test_create_workspace_with_isoformat_string(self):
workspace = WorkspaceModel(
name="workspace",
inserted_at="2024-12-12T09:44:24.989000Z",
updated_at="2024-12-12T09:44:24.989000Z",
)

expected_datetime = datetime(2024, 12, 12, 9, 44, 24, 989000, tzinfo=tz.tzutc())

assert workspace.name == "workspace"

assert workspace.inserted_at == expected_datetime
assert workspace.updated_at == expected_datetime
Loading