Skip to content

Commit 3f4be95

Browse files
authored
[ml] Make copy of featureset obj during create_update (#32367)
* Make copy of featureset obj during create * update dump * update test * update dump to work with py37
1 parent b20b870 commit 3f4be95

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

sdk/ml/azure-ai-ml/azure/ai/ml/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
load_data,
2525
load_datastore,
2626
load_environment,
27+
load_feature_set,
28+
load_feature_store,
29+
load_feature_store_entity,
2730
load_job,
2831
load_model,
2932
load_model_package,
@@ -58,6 +61,9 @@
5861
"load_compute",
5962
"load_data",
6063
"load_datastore",
64+
"load_feature_set",
65+
"load_feature_store",
66+
"load_feature_store_entity",
6167
"load_model",
6268
"load_environment",
6369
"load_job",

sdk/ml/azure-ai-ml/azure/ai/ml/entities/_assets/_artifacts/feature_set.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,13 @@ def dump(self, dest: Union[str, PathLike, IO[AnyStr]], **kwargs) -> None:
206206

207207
origin_spec_path = self.specification.path
208208
if isinstance(dest, (PathLike, str)) and not is_url(self.specification.path):
209+
if os.path.exists(dest):
210+
raise FileExistsError(f"File {dest} already exists.")
209211
relative_path = os.path.basename(self.specification.path)
210212
src_spec_path = str(Path(self._base_path, self.specification.path))
211213
dest_spec_path = str(Path(os.path.dirname(dest), relative_path))
214+
if os.path.exists(dest_spec_path):
215+
shutil.rmtree(dest_spec_path)
212216
shutil.copytree(src=src_spec_path, dst=dest_spec_path)
213217
self.specification.path = str(Path("./", relative_path))
214218
super().dump(dest=dest, **kwargs)

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_feature_set_operations.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
import json
88
import os
9+
from copy import deepcopy
910
from datetime import datetime
1011
from pathlib import Path
11-
from typing import Dict, Optional, Union, List
12+
from typing import Dict, List, Optional, Union
1213

1314
from marshmallow.exceptions import ValidationError as SchemaValidationError
1415

@@ -151,23 +152,24 @@ def begin_create_or_update(self, featureset: FeatureSet, **kwargs: Dict) -> LROP
151152
:return: An instance of LROPoller that returns a FeatureSet.
152153
:rtype: ~azure.core.polling.LROPoller[~azure.ai.ml.entities.FeatureSet]
153154
"""
155+
featureset_copy = deepcopy(featureset)
154156

155-
featureset_spec = self._validate_and_get_feature_set_spec(featureset)
156-
featureset.properties["featuresetPropertiesVersion"] = "1"
157-
featureset.properties["featuresetProperties"] = json.dumps(featureset_spec._to_dict())
157+
featureset_spec = self._validate_and_get_feature_set_spec(featureset_copy)
158+
featureset_copy.properties["featuresetPropertiesVersion"] = "1"
159+
featureset_copy.properties["featuresetProperties"] = json.dumps(featureset_spec._to_dict())
158160

159161
sas_uri = None
160-
featureset, _ = _check_and_upload_path(
161-
artifact=featureset, asset_operations=self, sas_uri=sas_uri, artifact_type=ErrorTarget.FEATURE_SET
162+
featureset_copy, _ = _check_and_upload_path(
163+
artifact=featureset_copy, asset_operations=self, sas_uri=sas_uri, artifact_type=ErrorTarget.FEATURE_SET
162164
)
163165

164-
featureset_resource = FeatureSet._to_rest_object(featureset)
166+
featureset_resource = FeatureSet._to_rest_object(featureset_copy)
165167

166168
return self._operation.begin_create_or_update(
167169
resource_group_name=self._resource_group_name,
168170
workspace_name=self._workspace_name,
169-
name=featureset.name,
170-
version=featureset.version,
171+
name=featureset_copy.name,
172+
version=featureset_copy.version,
171173
body=featureset_resource,
172174
**kwargs,
173175
cls=lambda response, deserialized, headers: FeatureSet._from_rest_object(deserialized),

0 commit comments

Comments
 (0)