-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathtest_fetch.py
More file actions
61 lines (51 loc) · 1.96 KB
/
test_fetch.py
File metadata and controls
61 lines (51 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from feast import FeatureStore
store = FeatureStore(repo_path=".")
import pandas as pd
from datetime import datetime
def run_demo():
store = FeatureStore(repo_path=".")
print("--- Historical features ---")
entity_df = pd.DataFrame.from_dict(
{
"driver_id": [1001, 1002, 1003, 1004],
"event_timestamp": [
datetime(2021, 4, 12, 10, 59, 42),
datetime(2021, 4, 12, 8, 12, 10),
datetime(2021, 4, 12, 16, 40, 26),
datetime(2021, 4, 12, 15, 1, 12),
],
"val_to_add": [1, 2, 3, 4],
"val_to_add_2": [10, 20, 30, 40],
}
)
training_df = store.get_historical_features(
entity_df=entity_df, features=store.get_feature_service("model_v2"),
).to_df()
print(training_df.head())
print("\n--- Online features ---")
features = store.get_online_features(
features=store.get_feature_service("model_v2"),
entity_rows=[{"driver_id": 1001, "val_to_add": 1000, "val_to_add_2": 2000,}],
).to_dict()
for key, value in sorted(features.items()):
print(key, " : ", value)
print("\n--- Simulate a stream event ingestion via the daily stats push source ---")
event_df = pd.DataFrame.from_dict(
{
"driver_id": [1001],
"event_timestamp": [datetime(2021, 5, 13, 10, 59, 42),],
"created": [datetime(2021, 5, 13, 10, 59, 42),],
"daily_miles_driven": [1234],
}
)
print(event_df)
store.push("driver_stats_push_source", event_df)
print("\n--- Online features again with updated values from a stream push---")
features = store.get_online_features(
features=store.get_feature_service("model_v2"),
entity_rows=[{"driver_id": 1001, "val_to_add": 1000, "val_to_add_2": 2000,}],
).to_dict()
for key, value in sorted(features.items()):
print(key, " : ", value)
if __name__ == "__main__":
run_demo()