Skip to content

Commit

Permalink
Add method to add feature to Feature table (#1068)
Browse files Browse the repository at this point in the history
* Add method to add feature

Signed-off-by: Terence <[email protected]>

* Remove outdated tutorial

Signed-off-by: Terence <[email protected]>

* Revert "Remove outdated tutorial"

This reverts commit c5bdc90.

Signed-off-by: Terence <[email protected]>
  • Loading branch information
terryyylim authored Oct 19, 2020
1 parent 029d9ab commit 2060053
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
6 changes: 6 additions & 0 deletions sdk/python/feast/feature_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ def last_updated_timestamp(self):
"""
return self._last_updated_timestamp

def add_feature(self, feature: Feature):
"""
Adds a new feature to the feature table.
"""
self.features.append(feature)

def is_valid(self):
"""
Validates the state of a feature table locally. Raises an exception
Expand Down
33 changes: 30 additions & 3 deletions sdk/python/tests/test_feature_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def server(self):
def client(self, server):
return Client(core_url=f"localhost:{free_port}")

def test_feature_table_import_export_yaml(self):

batch_source = FileSource(
@pytest.fixture
def batch_source(self):
return FileSource(
field_mapping={
"ride_distance": "ride_distance",
"ride_duration": "ride_duration",
Expand All @@ -67,6 +67,8 @@ def test_feature_table_import_export_yaml(self):
date_partition_column="date_partition_col",
)

def test_feature_table_import_export_yaml(self, batch_source):

stream_source = KafkaSource(
field_mapping={
"ride_distance": "ride_distance",
Expand Down Expand Up @@ -99,3 +101,28 @@ def test_feature_table_import_export_yaml(self):

# Ensure equality is upheld to original feature table
assert test_feature_table == actual_feature_table_from_string

def test_add_feature(self, batch_source):

test_feature_table = FeatureTable(
name="car_driver",
features=[
Feature(name="ride_distance", dtype=ValueType.FLOAT),
Feature(name="ride_duration", dtype=ValueType.STRING),
],
entities=["car_driver_entity"],
labels={"team": "matchmaking"},
batch_source=batch_source,
)

test_feature_table.add_feature(
Feature(name="new_ride_distance", dtype=ValueType.FLOAT)
)

features = test_feature_table.features
assert (
len(features) == 3
and features[0].name == "ride_distance"
and features[1].name == "ride_duration"
and features[2].name == "new_ride_distance"
)

0 comments on commit 2060053

Please sign in to comment.