Defines an online response in feast.
| 35 | |
| 36 | |
| 37 | class OnlineResponse: |
| 38 | """ |
| 39 | Defines an online response in feast. |
| 40 | """ |
| 41 | |
| 42 | def __init__( |
| 43 | self, |
| 44 | online_response_proto: GetOnlineFeaturesResponse, |
| 45 | feature_types: Optional[Dict[str, ValueType]] = None, |
| 46 | ): |
| 47 | """ |
| 48 | Construct a native online response from its protobuf version. |
| 49 | |
| 50 | Args: |
| 51 | online_response_proto: GetOnlineResponse proto object to construct from. |
| 52 | feature_types: Optional mapping of feature names to ValueType for type-aware deserialization. |
| 53 | """ |
| 54 | self.proto = online_response_proto |
| 55 | self._feature_types = feature_types or {} |
| 56 | # Delete DUMMY_ENTITY_ID from proto if it exists |
| 57 | for idx, val in enumerate(self.proto.metadata.feature_names.val): |
| 58 | if val == DUMMY_ENTITY_ID: |
| 59 | del self.proto.metadata.feature_names.val[idx] |
| 60 | del self.proto.results[idx] |
| 61 | |
| 62 | break |
| 63 | |
| 64 | def to_dict(self, include_event_timestamps: bool = False) -> Dict[str, Any]: |
| 65 | """ |
| 66 | Converts GetOnlineFeaturesResponse features into a dictionary form. |
| 67 | |
| 68 | Args: |
| 69 | include_event_timestamps: bool Optionally include feature timestamps in the dictionary |
| 70 | """ |
| 71 | response: Dict[str, List[Any]] = {} |
| 72 | |
| 73 | for feature_ref, feature_vector in zip( |
| 74 | self.proto.metadata.feature_names.val, self.proto.results |
| 75 | ): |
| 76 | feature_type = self._feature_types.get(feature_ref) |
| 77 | response[feature_ref] = [ |
| 78 | feast_value_type_to_python_type(v, feature_type) |
| 79 | for v in feature_vector.values |
| 80 | ] |
| 81 | |
| 82 | if include_event_timestamps: |
| 83 | timestamp_ref = feature_ref + TIMESTAMP_POSTFIX |
| 84 | response[timestamp_ref] = [ |
| 85 | ts.seconds for ts in feature_vector.event_timestamps |
| 86 | ] |
| 87 | |
| 88 | return response |
| 89 | |
| 90 | def to_df(self, include_event_timestamps: bool = False) -> pd.DataFrame: |
| 91 | """ |
| 92 | Converts GetOnlineFeaturesResponse features into Panda dataframe form. |
| 93 | |
| 94 | Args: |
no outgoing calls