Skip to content

Commit

Permalink
fix: Fixing failure of protos during ODFV transformations for missing…
Browse files Browse the repository at this point in the history
… entities (feast-dev#4667)
  • Loading branch information
franciscojavierarceo authored and emgeee committed Oct 23, 2024
1 parent 1c89999 commit b492941
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
24 changes: 19 additions & 5 deletions sdk/python/feast/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from feast.protos.feast.types.Value_pb2 import RepeatedValue as RepeatedValueProto
from feast.protos.feast.types.Value_pb2 import Value as ValueProto
from feast.type_map import python_values_to_proto_values
from feast.types import from_feast_to_pyarrow_type
from feast.types import ComplexFeastType, PrimitiveFeastType, from_feast_to_pyarrow_type
from feast.value_type import ValueType
from feast.version import get_version

Expand Down Expand Up @@ -552,13 +552,27 @@ def _augment_response_with_on_demand_transforms(
selected_subset = [f for f in transformed_columns if f in _feature_refs]

proto_values = []
schema_dict = {k.name: k.dtype for k in odfv.schema}
for selected_feature in selected_subset:
feature_vector = transformed_features[selected_feature]
selected_feature_type = schema_dict.get(selected_feature, None)
feature_type: ValueType = ValueType.UNKNOWN
if selected_feature_type is not None:
if isinstance(
selected_feature_type, (ComplexFeastType, PrimitiveFeastType)
):
feature_type = selected_feature_type.to_value_type()
elif not isinstance(selected_feature_type, ValueType):
raise TypeError(
f"Unexpected type for feature_type: {type(feature_type)}"
)

proto_values.append(
python_values_to_proto_values(feature_vector, ValueType.UNKNOWN)
if odfv.mode == "python"
else python_values_to_proto_values(
feature_vector.to_numpy(), ValueType.UNKNOWN
python_values_to_proto_values(
feature_vector
if odfv.mode == "python"
else feature_vector.to_numpy(),
feature_type,
)
)

Expand Down
26 changes: 13 additions & 13 deletions sdk/python/tests/unit/test_on_demand_python_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,19 +609,19 @@ def pandas_view(features_df: pd.DataFrame) -> pd.DataFrame:
"val_to_add",
"val_to_add_2",
]
with pytest.raises(TypeError):
_ = self.store.get_online_features(
entity_rows=[
{"driver_id": 1234567890, "val_to_add": 0, "val_to_add_2": 1}
],
features=[
"driver_hourly_stats:conv_rate",
"driver_hourly_stats:acc_rate",
"driver_hourly_stats:avg_daily_trips",
"pandas_view:conv_rate_plus_val1",
"pandas_view:conv_rate_plus_val2",
],
)
resp_online_missing_entity = self.store.get_online_features(
entity_rows=[
{"driver_id": 1234567890, "val_to_add": 0, "val_to_add_2": 1}
],
features=[
"driver_hourly_stats:conv_rate",
"driver_hourly_stats:acc_rate",
"driver_hourly_stats:avg_daily_trips",
"pandas_view:conv_rate_plus_val1",
"pandas_view:conv_rate_plus_val2",
],
)
assert resp_online_missing_entity is not None
resp_online = self.store.get_online_features(
entity_rows=[{"driver_id": 1001, "val_to_add": 0, "val_to_add_2": 1}],
features=[
Expand Down

0 comments on commit b492941

Please sign in to comment.