Content-Length: 643824 | pFad | https://github.com/googleapis/python-aiplatform/commit/5ee6354a12c6422015acb81caef32d6d2f52c838

46 docs(samples): add samples to create/delete featurestore (#980) · googleapis/python-aiplatform@5ee6354 · GitHub
Skip to content

Commit 5ee6354

Browse files
docs(samples): add samples to create/delete featurestore (#980)
* feat: SDK feature store samples (create/delete fs) * feat: adding to conftest.py * docs(samples): fixed testing * docs(samples): fixed testing * docs(samples): fixed testing * docs(samples) added changes * docs(samples): style issues * Update samples/model-builder/create_featurestore_sample_test.py Co-authored-by: Morgan Du <morgandu@google.com> * Update samples/model-builder/test_constants.py Co-authored-by: Morgan Du <morgandu@google.com> * Update samples/model-builder/create_featurestore_sample_test.py Co-authored-by: Morgan Du <morgandu@google.com> Co-authored-by: Morgan Du <morgandu@google.com>
1 parent 095bea2 commit 5ee6354

File tree

6 files changed

+195
-0
lines changed

6 files changed

+195
-0
lines changed

samples/model-builder/conftest.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,38 @@ def mock_endpoint_explain(mock_endpoint):
364364
with patch.object(mock_endpoint, "explain") as mock_endpoint_explain:
365365
mock_get_endpoint.return_value = mock_endpoint
366366
yield mock_endpoint_explain
367+
368+
369+
"""
370+
----------------------------------------------------------------------------
371+
FeatureStore Fixtures
372+
----------------------------------------------------------------------------
373+
"""
374+
375+
376+
@pytest.fixture
377+
def mock_featurestore():
378+
mock = MagicMock(aiplatform.featurestore.Featurestore)
379+
yield mock
380+
381+
382+
@pytest.fixture
383+
def mock_get_featurestore(mock_featurestore):
384+
with patch.object(aiplatform.featurestore, "Featurestore") as mock_get_featurestore:
385+
mock_get_featurestore.return_value = mock_featurestore
386+
yield mock_get_featurestore
387+
388+
389+
@pytest.fixture
390+
def mock_create_featurestore(mock_featurestore):
391+
with patch.object(
392+
aiplatform.featurestore.Featurestore, "create"
393+
) as mock_create_featurestore:
394+
mock_create_featurestore.return_value = mock_featurestore
395+
yield mock_create_featurestore
396+
397+
398+
@pytest.fixture
399+
def mock_delete_featurestore(mock_featurestore):
400+
with patch.object(mock_featurestore, "delete") as mock_delete_featurestore:
401+
yield mock_delete_featurestore
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
# [START aiplatform_sdk_create_featurestore_sample]
17+
from google.cloud import aiplatform
18+
19+
20+
def create_featurestore_sample(
21+
project: str,
22+
location: str,
23+
featurestore_id: str,
24+
online_store_fixed_node_count: int = 1,
25+
sync: bool = True,
26+
):
27+
28+
aiplatform.init(project=project, location=location)
29+
30+
fs = aiplatform.Featurestore.create(
31+
featurestore_id=featurestore_id,
32+
online_store_fixed_node_count=online_store_fixed_node_count,
33+
sync=sync,
34+
)
35+
36+
fs.wait()
37+
38+
return fs
39+
40+
41+
# [END aiplatform_sdk_create_featurestore_sample]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import create_featurestore_sample
16+
import test_constants as constants
17+
18+
19+
def test_create_featurestore_sample(mock_sdk_init, mock_create_featurestore):
20+
21+
create_featurestore_sample.create_featurestore_sample(
22+
project=constants.PROJECT,
23+
location=constants.LOCATION,
24+
featurestore_id=constants.FEAUTURESTORE_ID,
25+
online_store_fixed_node_count=constants.ONLINE_STORE_FIXED_NODE_COUNT,
26+
sync=constants.SYNC,
27+
)
28+
29+
mock_sdk_init.assert_called_once_with(
30+
project=constants.PROJECT, location=constants.LOCATION
31+
)
32+
33+
mock_create_featurestore.assert_called_once_with(
34+
featurestore_id=constants.FEAUTURESTORE_ID,
35+
online_store_fixed_node_count=constants.ONLINE_STORE_FIXED_NODE_COUNT,
36+
sync=constants.SYNC,
37+
)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
# [START aiplatform_sdk_delete_featurestore_sample]
17+
from google.cloud import aiplatform
18+
19+
20+
def delete_featurestore_sample(
21+
project: str,
22+
location: str,
23+
featurestore_name: str,
24+
sync: bool = True,
25+
force: bool = True,
26+
):
27+
28+
aiplatform.init(project=project, location=location)
29+
30+
fs = aiplatform.featurestore.Featurestore(featurestore_name=featurestore_name)
31+
fs.delete(sync=sync, force=force)
32+
33+
34+
# [END aiplatform_sdk_delete_featurestore_sample]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import delete_featurestore_sample
16+
import test_constants as constants
17+
18+
19+
def test_delete_featurestore_sample(
20+
mock_sdk_init, mock_get_featurestore, mock_delete_featurestore
21+
):
22+
23+
delete_featurestore_sample.delete_featurestore_sample(
24+
project=constants.PROJECT,
25+
location=constants.LOCATION,
26+
featurestore_name=constants.FEAUTURESTORE_NAME,
27+
sync=constants.SYNC,
28+
force=constants.FORCE,
29+
)
30+
31+
mock_sdk_init.assert_called_once_with(
32+
project=constants.PROJECT, location=constants.LOCATION
33+
)
34+
35+
mock_get_featurestore.assert_called_once_with(
36+
featurestore_name=constants.FEAUTURESTORE_NAME
37+
)
38+
39+
mock_delete_featurestore.assert_called_once_with(
40+
sync=constants.SYNC, force=constants.FORCE
41+
)

samples/model-builder/test_constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,10 @@
197197
)
198198
PYTHON_MODULE_NAME = "trainer.task"
199199
MODEL_TYPE = "CLOUD"
200+
201+
# Feature store constants
202+
FEAUTURESTORE_NAME = "projects/123/locations/us-central1/featurestores/featurestore_id"
203+
FEAUTURESTORE_ID = "featurestore_id"
204+
ONLINE_STORE_FIXED_NODE_COUNT = 1
205+
SYNC = True
206+
FORCE = True

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/googleapis/python-aiplatform/commit/5ee6354a12c6422015acb81caef32d6d2f52c838

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy