Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to add feature to Feature table #1068

Merged
merged 3 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -52,9 +52,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 @@ -66,6 +66,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 @@ -98,3 +100,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"
)