From 932220cbbec9527eca5f04182a804fde111a9c11 Mon Sep 17 00:00:00 2001 From: dk Date: Tue, 18 Jun 2024 10:50:19 +0700 Subject: [PATCH 1/2] [syft/dataset] wrap data and mock with `ActionObject.from_obj` before uploading `TwinObject` --- packages/syft/src/syft/client/domain_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/syft/src/syft/client/domain_client.py b/packages/syft/src/syft/client/domain_client.py index 1c768710040..a23a4c44170 100644 --- a/packages/syft/src/syft/client/domain_client.py +++ b/packages/syft/src/syft/client/domain_client.py @@ -129,8 +129,8 @@ def upload_dataset(self, dataset: CreateDataset) -> SyftSuccess | SyftError: for asset in dataset.asset_list: try: twin = TwinObject( - private_obj=asset.data, - mock_obj=asset.mock, + private_obj=ActionObject.from_obj(asset.data), + mock_obj=ActionObject.from_obj(asset.mock), syft_node_location=self.id, syft_client_verify_key=self.verify_key, ) From 2a0a4eb299cdebca0033267b14e2823d7910bca7 Mon Sep 17 00:00:00 2001 From: dk Date: Tue, 18 Jun 2024 15:18:51 +0700 Subject: [PATCH 2/2] [syft/tests] test uploading assetes with different data types: int | str | dict | set | np.ndarray | pd.DataFrame | torch.Tensor --- .../service/dataset/dataset_service_test.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/packages/syft/tests/syft/service/dataset/dataset_service_test.py b/packages/syft/tests/syft/service/dataset/dataset_service_test.py index a60bc653c13..1aa85c07865 100644 --- a/packages/syft/tests/syft/service/dataset/dataset_service_test.py +++ b/packages/syft/tests/syft/service/dataset/dataset_service_test.py @@ -5,8 +5,10 @@ # third party import numpy as np +import pandas as pd from pydantic import ValidationError import pytest +import torch # syft absolute import syft as sy @@ -253,3 +255,49 @@ def test_adding_contributors_with_duplicate_email(): assert isinstance(res3, SyftSuccess) assert isinstance(res4, SyftError) assert len(asset.contributors) == 1 + + +@pytest.fixture( + params=[ + 1, + "hello", + {"key": "value"}, + {1, 2, 3}, + np.array([1, 2, 3]), + pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]}), + torch.Tensor([1, 2, 3]), + ] +) +def different_data_types( + request, +) -> int | str | dict | set | np.ndarray | pd.DataFrame | torch.Tensor: + return request.param + + +def test_upload_dataset_with_assets_of_different_data_types( + worker: Worker, + different_data_types: int + | str + | dict + | set + | np.ndarray + | pd.DataFrame + | torch.Tensor, +) -> None: + asset = sy.Asset( + name=random_hash(), + data=different_data_types, + mock=different_data_types, + ) + dataset = Dataset(name=random_hash()) + dataset.add_asset(asset) + root_domain_client = worker.root_client + res = root_domain_client.upload_dataset(dataset) + assert isinstance(res, SyftSuccess) + assert len(root_domain_client.api.services.dataset.get_all()) == 1 + assert type(root_domain_client.datasets[0].assets[0].data) == type( + different_data_types + ) + assert type(root_domain_client.datasets[0].assets[0].mock) == type( + different_data_types + )