Skip to content

Commit c40d539

Browse files
feat: Adding mode='python' for get_historical_features on ODFVs (#4653)
1 parent 15e4808 commit c40d539

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

sdk/python/feast/transformation/python_transformation.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def __init__(self, udf: FunctionType, udf_string: str = ""):
2626
self.udf_string = udf_string
2727

2828
def transform_arrow(
29-
self, pa_table: pyarrow.Table, features: list[Field]
29+
self,
30+
pa_table: pyarrow.Table,
31+
features: list[Field],
3032
) -> pyarrow.Table:
31-
raise Exception(
32-
'OnDemandFeatureView with mode "python" does not support offline processing.'
33-
)
33+
return pyarrow.Table.from_pydict(self.udf(pa_table.to_pydict()))
3434

3535
def transform(self, input_dict: dict) -> dict:
3636
# Ensuring that the inputs are included as well

sdk/python/tests/unit/test_on_demand_python_transformation.py

+18
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,24 @@ def pandas_view(features_df: pd.DataFrame) -> pd.DataFrame:
561561
assert resp is not None
562562
assert resp["conv_rate_plus_val1"].isnull().sum() == 0
563563

564+
batch_sample["avg_daily_trip_rank_thresholds"] = [
565+
[100, 250, 500, 1000]
566+
] * batch_sample.shape[0]
567+
batch_sample["avg_daily_trip_rank_names"] = [
568+
["Bronze", "Silver", "Gold", "Platinum"]
569+
] * batch_sample.shape[0]
570+
resp_python = self.store.get_historical_features(
571+
entity_df=batch_sample,
572+
features=[
573+
"driver_hourly_stats:conv_rate",
574+
"driver_hourly_stats:acc_rate",
575+
"driver_hourly_stats:avg_daily_trips",
576+
"python_view:conv_rate_plus_acc",
577+
],
578+
).to_df()
579+
assert resp_python is not None
580+
assert resp_python["conv_rate_plus_acc"].isnull().sum() == 0
581+
564582
# Now testing feature retrieval for driver ids not in the dataset
565583
missing_batch_sample = pd.DataFrame([1234567890], columns=["driver_id"])
566584
missing_batch_sample["val_to_add"] = 0

0 commit comments

Comments
 (0)