-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix on demand feature view crash from inference when it uses df.…
…apply (#2713) * fix: Fix on demand feature view crash from inference when transformation uses df.apply Signed-off-by: Danny Chiao <[email protected]> * Fix inference Signed-off-by: Danny Chiao <[email protected]> * Fix test Signed-off-by: Danny Chiao <[email protected]>
- Loading branch information
Showing
4 changed files
with
168 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
sdk/python/tests/example_repos/on_demand_feature_view_repo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from datetime import timedelta | ||
|
||
import pandas as pd | ||
|
||
from feast import FeatureView, Field, FileSource | ||
from feast.on_demand_feature_view import on_demand_feature_view | ||
from feast.types import Float32, String | ||
|
||
driver_stats = FileSource( | ||
name="driver_stats_source", | ||
path="data/driver_stats_lat_lon.parquet", | ||
timestamp_field="event_timestamp", | ||
created_timestamp_column="created", | ||
description="A table describing the stats of a driver based on hourly logs", | ||
owner="[email protected]", | ||
) | ||
|
||
driver_daily_features_view = FeatureView( | ||
name="driver_daily_features", | ||
entities=["driver"], | ||
ttl=timedelta(seconds=8640000000), | ||
schema=[ | ||
Field(name="daily_miles_driven", dtype=Float32), | ||
Field(name="lat", dtype=Float32), | ||
Field(name="lon", dtype=Float32), | ||
Field(name="string_feature", dtype=String), | ||
], | ||
online=True, | ||
source=driver_stats, | ||
tags={"production": "True"}, | ||
owner="[email protected]", | ||
) | ||
|
||
|
||
@on_demand_feature_view( | ||
sources=[driver_daily_features_view], | ||
schema=[ | ||
Field(name="first_char", dtype=String), | ||
Field(name="concat_string", dtype=String), | ||
], | ||
) | ||
def location_features_from_push(inputs: pd.DataFrame) -> pd.DataFrame: | ||
df = pd.DataFrame() | ||
df["concat_string"] = inputs.apply( | ||
lambda x: x.string_feature + "hello", axis=1 | ||
).astype("string") | ||
df["first_char"] = inputs["string_feature"].str[:1].astype("string") | ||
return df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,6 +234,80 @@ def test_apply_feature_view_success(test_registry): | |
test_registry._get_registry_proto() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_registry", [lazy_fixture("local_registry")], | ||
) | ||
def test_apply_on_demand_feature_view_success(test_registry): | ||
# Create Feature Views | ||
driver_stats = FileSource( | ||
name="driver_stats_source", | ||
path="data/driver_stats_lat_lon.parquet", | ||
timestamp_field="event_timestamp", | ||
created_timestamp_column="created", | ||
description="A table describing the stats of a driver based on hourly logs", | ||
owner="[email protected]", | ||
) | ||
|
||
driver_daily_features_view = FeatureView( | ||
name="driver_daily_features", | ||
entities=["driver"], | ||
ttl=timedelta(seconds=8640000000), | ||
schema=[ | ||
Field(name="daily_miles_driven", dtype=Float32), | ||
Field(name="lat", dtype=Float32), | ||
Field(name="lon", dtype=Float32), | ||
Field(name="string_feature", dtype=String), | ||
], | ||
online=True, | ||
source=driver_stats, | ||
tags={"production": "True"}, | ||
owner="[email protected]", | ||
) | ||
|
||
@on_demand_feature_view( | ||
sources=[driver_daily_features_view], | ||
schema=[Field(name="first_char", dtype=String)], | ||
) | ||
def location_features_from_push(inputs: pd.DataFrame) -> pd.DataFrame: | ||
df = pd.DataFrame() | ||
df["first_char"] = inputs["string_feature"].str[:1].astype("string") | ||
return df | ||
|
||
project = "project" | ||
|
||
# Register Feature View | ||
test_registry.apply_feature_view(location_features_from_push, project) | ||
|
||
feature_views = test_registry.list_on_demand_feature_views(project) | ||
|
||
# List Feature Views | ||
assert ( | ||
len(feature_views) == 1 | ||
and feature_views[0].name == "location_features_from_push" | ||
and feature_views[0].features[0].name == "first_char" | ||
and feature_views[0].features[0].dtype == String | ||
) | ||
|
||
feature_view = test_registry.get_on_demand_feature_view( | ||
"location_features_from_push", project | ||
) | ||
assert ( | ||
feature_view.name == "location_features_from_push" | ||
and feature_view.features[0].name == "first_char" | ||
and feature_view.features[0].dtype == String | ||
) | ||
|
||
test_registry.delete_feature_view("location_features_from_push", project) | ||
feature_views = test_registry.list_on_demand_feature_views(project) | ||
assert len(feature_views) == 0 | ||
|
||
test_registry.teardown() | ||
|
||
# Will try to reload registry, which will fail because the file has been deleted | ||
with pytest.raises(FileNotFoundError): | ||
test_registry._get_registry_proto() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"test_registry", [lazy_fixture("local_registry")], | ||
) | ||
|