Skip to content

Commit

Permalink
chore: add Feature listing
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 636237992
  • Loading branch information
vertex-sdk-bot authored and Copybara-Service committed May 22, 2024
1 parent 9936514 commit 0936f35
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/unit/vertexai/feature_store_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,5 @@
labels=_TEST_FG1_F2_LABELS,
point_of_contact=_TEST_FG1_F2_POINT_OF_CONTACT,
)

_TEST_FG1_FEATURE_LIST = [_TEST_FG1_F1, _TEST_FG1_F2]
41 changes: 41 additions & 0 deletions tests/unit/vertexai/test_feature_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
_TEST_FG1_F2_LABELS,
_TEST_FG1_F2_POINT_OF_CONTACT,
_TEST_FG1_F2_VERSION_COLUMN_NAME,
_TEST_FG1_FEATURE_LIST,
)
from test_feature import feature_eq

Expand Down Expand Up @@ -157,6 +158,16 @@ def create_feature_with_version_column_mock():
yield create_feature_mock


@pytest.fixture
def list_features_mock():
with patch.object(
feature_registry_service_client.FeatureRegistryServiceClient,
"list_features",
) as list_features_mock:
list_features_mock.return_value = _TEST_FG1_FEATURE_LIST
yield list_features_mock


def fg_eq(
fg_to_check: FeatureGroup,
name: str,
Expand Down Expand Up @@ -530,3 +541,33 @@ def test_create_feature_with_version_feature_column(
),
]
)


def test_list_features(get_fg_mock, list_features_mock):
aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION)

features = FeatureGroup(_TEST_FG1_ID).list_features()

list_features_mock.assert_called_once_with(request={"parent": _TEST_FG1_PATH})
assert len(features) == len(_TEST_FG1_FEATURE_LIST)
feature_eq(
features[0],
name=_TEST_FG1_F1_ID,
resource_name=_TEST_FG1_F1_PATH,
project=_TEST_PROJECT,
location=_TEST_LOCATION,
description=_TEST_FG1_F1_DESCRIPTION,
labels=_TEST_FG1_F1_LABELS,
point_of_contact=_TEST_FG1_F1_POINT_OF_CONTACT,
)
feature_eq(
features[1],
name=_TEST_FG1_F2_ID,
resource_name=_TEST_FG1_F2_PATH,
project=_TEST_PROJECT,
location=_TEST_LOCATION,
description=_TEST_FG1_F2_DESCRIPTION,
labels=_TEST_FG1_F2_LABELS,
point_of_contact=_TEST_FG1_F2_POINT_OF_CONTACT,
version_column_name=_TEST_FG1_F2_VERSION_COLUMN_NAME,
)
30 changes: 30 additions & 0 deletions vertexai/resources/preview/feature_store/feature_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,36 @@ def create_feature(

return feature_obj

def list_features(
self,
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
) -> List[Feature]:
"""Lists features under this feature group.
Args:
project:
Project to create feature in. If unset, the project set in
aiplatform.init will be used.
location:
Location to create feature in. If not set, location set in
aiplatform.init will be used.
credentials:
Custom credentials to use to create this feature. Overrides
credentials set in aiplatform.init.
Returns:
List of features under this feature group.
"""

return Feature.list(
parent=self.resource_name,
project=project,
location=location,
credentials=credentials,
)

@property
def source(self) -> FeatureGroupBigQuerySource:
return FeatureGroupBigQuerySource(
Expand Down

0 comments on commit 0936f35

Please sign in to comment.