Skip to content

Commit 2060053

Browse files
authored
Add method to add feature to Feature table (#1068)
* Add method to add feature Signed-off-by: Terence <terencelimxp@gmail.com> * Remove outdated tutorial Signed-off-by: Terence <terencelimxp@gmail.com> * Revert "Remove outdated tutorial" This reverts commit c5bdc90. Signed-off-by: Terence <terencelimxp@gmail.com>
1 parent 029d9ab commit 2060053

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

sdk/python/feast/feature_table.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ def last_updated_timestamp(self):
206206
"""
207207
return self._last_updated_timestamp
208208

209+
def add_feature(self, feature: Feature):
210+
"""
211+
Adds a new feature to the feature table.
212+
"""
213+
self.features.append(feature)
214+
209215
def is_valid(self):
210216
"""
211217
Validates the state of a feature table locally. Raises an exception

sdk/python/tests/test_feature_table.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ def server(self):
5353
def client(self, server):
5454
return Client(core_url=f"localhost:{free_port}")
5555

56-
def test_feature_table_import_export_yaml(self):
57-
58-
batch_source = FileSource(
56+
@pytest.fixture
57+
def batch_source(self):
58+
return FileSource(
5959
field_mapping={
6060
"ride_distance": "ride_distance",
6161
"ride_duration": "ride_duration",
@@ -67,6 +67,8 @@ def test_feature_table_import_export_yaml(self):
6767
date_partition_column="date_partition_col",
6868
)
6969

70+
def test_feature_table_import_export_yaml(self, batch_source):
71+
7072
stream_source = KafkaSource(
7173
field_mapping={
7274
"ride_distance": "ride_distance",
@@ -99,3 +101,28 @@ def test_feature_table_import_export_yaml(self):
99101

100102
# Ensure equality is upheld to original feature table
101103
assert test_feature_table == actual_feature_table_from_string
104+
105+
def test_add_feature(self, batch_source):
106+
107+
test_feature_table = FeatureTable(
108+
name="car_driver",
109+
features=[
110+
Feature(name="ride_distance", dtype=ValueType.FLOAT),
111+
Feature(name="ride_duration", dtype=ValueType.STRING),
112+
],
113+
entities=["car_driver_entity"],
114+
labels={"team": "matchmaking"},
115+
batch_source=batch_source,
116+
)
117+
118+
test_feature_table.add_feature(
119+
Feature(name="new_ride_distance", dtype=ValueType.FLOAT)
120+
)
121+
122+
features = test_feature_table.features
123+
assert (
124+
len(features) == 3
125+
and features[0].name == "ride_distance"
126+
and features[1].name == "ride_duration"
127+
and features[2].name == "new_ride_distance"
128+
)

0 commit comments

Comments
 (0)