|
17 | 17 | import pandas as pd |
18 | 18 | import pytest |
19 | 19 |
|
| 20 | +from feast.data_source import RequestSource |
20 | 21 | from feast.feature_view import FeatureView |
21 | 22 | from feast.field import Field |
22 | 23 | from feast.infra.offline_stores.file_source import FileSource |
|
26 | 27 | PythonTransformation, |
27 | 28 | on_demand_feature_view, |
28 | 29 | ) |
29 | | -from feast.types import Float32 |
| 30 | +from feast.types import Float32, String |
30 | 31 |
|
31 | 32 |
|
32 | 33 | def udf1(features_df: pd.DataFrame) -> pd.DataFrame: |
@@ -418,3 +419,40 @@ def another_transform(features_df: pd.DataFrame) -> pd.DataFrame: |
418 | 419 |
|
419 | 420 | deserialized = OnDemandFeatureView.from_proto(proto) |
420 | 421 | assert deserialized.name == CUSTOM_FUNCTION_NAME |
| 422 | + |
| 423 | + |
| 424 | +def test_on_demand_string_features(): |
| 425 | + """Test that on-demand feature views work with STRING type inputs from RequestSource.""" |
| 426 | + # Define a request data source with STRING type fields |
| 427 | + input_request = RequestSource( |
| 428 | + name="vals_to_add", |
| 429 | + schema=[ |
| 430 | + Field(name="val_to_add", dtype=String), |
| 431 | + Field(name="val_to_add_2", dtype=String), |
| 432 | + ], |
| 433 | + ) |
| 434 | + |
| 435 | + # Use input data to create new features in Pandas mode |
| 436 | + @on_demand_feature_view( |
| 437 | + sources=[input_request], |
| 438 | + schema=[ |
| 439 | + Field(name="conv_rate_plus_val1", dtype=String), |
| 440 | + Field(name="conv_rate_plus_val2", dtype=String), |
| 441 | + ], |
| 442 | + mode="pandas", |
| 443 | + ) |
| 444 | + def transformed_conv_rate(features_df: pd.DataFrame) -> pd.DataFrame: |
| 445 | + df = pd.DataFrame() |
| 446 | + df["conv_rate_plus_val1"] = features_df["val_to_add"] |
| 447 | + df["conv_rate_plus_val2"] = features_df["val_to_add_2"] |
| 448 | + return df |
| 449 | + |
| 450 | + # This should work without raising ValueError about 'object' type |
| 451 | + transformed_conv_rate.infer_features() |
| 452 | + |
| 453 | + # Verify the inferred features have the correct type |
| 454 | + assert len(transformed_conv_rate.features) == 2 |
| 455 | + assert transformed_conv_rate.features[0].name == "conv_rate_plus_val1" |
| 456 | + assert transformed_conv_rate.features[0].dtype == String |
| 457 | + assert transformed_conv_rate.features[1].name == "conv_rate_plus_val2" |
| 458 | + assert transformed_conv_rate.features[1].dtype == String |
0 commit comments