|
24 | 24 | OnDemandFeatureView,
|
25 | 25 | PandasTransformation,
|
26 | 26 | PythonTransformation,
|
| 27 | + on_demand_feature_view, |
27 | 28 | )
|
28 | 29 | from feast.types import Float32
|
29 | 30 |
|
@@ -356,3 +357,65 @@ def test_on_demand_feature_view_stored_writes():
|
356 | 357 | assert transformed_output["output3"] is not None and isinstance(
|
357 | 358 | transformed_output["output3"], datetime.datetime
|
358 | 359 | )
|
| 360 | + |
| 361 | + |
| 362 | +def test_function_call_syntax(): |
| 363 | + CUSTOM_FUNCTION_NAME = "custom-function-name" |
| 364 | + file_source = FileSource(name="my-file-source", path="test.parquet") |
| 365 | + feature_view = FeatureView( |
| 366 | + name="my-feature-view", |
| 367 | + entities=[], |
| 368 | + schema=[ |
| 369 | + Field(name="feature1", dtype=Float32), |
| 370 | + Field(name="feature2", dtype=Float32), |
| 371 | + ], |
| 372 | + source=file_source, |
| 373 | + ) |
| 374 | + sources = [feature_view] |
| 375 | + |
| 376 | + def transform_features(features_df: pd.DataFrame) -> pd.DataFrame: |
| 377 | + df = pd.DataFrame() |
| 378 | + df["output1"] = features_df["feature1"] |
| 379 | + df["output2"] = features_df["feature2"] |
| 380 | + return df |
| 381 | + |
| 382 | + odfv = on_demand_feature_view( |
| 383 | + sources=sources, |
| 384 | + schema=[ |
| 385 | + Field(name="output1", dtype=Float32), |
| 386 | + Field(name="output2", dtype=Float32), |
| 387 | + ], |
| 388 | + )(transform_features) |
| 389 | + |
| 390 | + assert odfv.name == transform_features.__name__ |
| 391 | + assert isinstance(odfv, OnDemandFeatureView) |
| 392 | + |
| 393 | + proto = odfv.to_proto() |
| 394 | + assert proto.spec.name == transform_features.__name__ |
| 395 | + |
| 396 | + deserialized = OnDemandFeatureView.from_proto(proto) |
| 397 | + assert deserialized.name == transform_features.__name__ |
| 398 | + |
| 399 | + def another_transform(features_df: pd.DataFrame) -> pd.DataFrame: |
| 400 | + df = pd.DataFrame() |
| 401 | + df["output1"] = features_df["feature1"] |
| 402 | + df["output2"] = features_df["feature2"] |
| 403 | + return df |
| 404 | + |
| 405 | + odfv_custom = on_demand_feature_view( |
| 406 | + name=CUSTOM_FUNCTION_NAME, |
| 407 | + sources=sources, |
| 408 | + schema=[ |
| 409 | + Field(name="output1", dtype=Float32), |
| 410 | + Field(name="output2", dtype=Float32), |
| 411 | + ], |
| 412 | + )(another_transform) |
| 413 | + |
| 414 | + assert odfv_custom.name == CUSTOM_FUNCTION_NAME |
| 415 | + assert isinstance(odfv_custom, OnDemandFeatureView) |
| 416 | + |
| 417 | + proto = odfv_custom.to_proto() |
| 418 | + assert proto.spec.name == CUSTOM_FUNCTION_NAME |
| 419 | + |
| 420 | + deserialized = OnDemandFeatureView.from_proto(proto) |
| 421 | + assert deserialized.name == CUSTOM_FUNCTION_NAME |
0 commit comments