MCPcopy Index your code
hub / github.com/feast-dev/feast / OnlineResponse

Class OnlineResponse

sdk/python/feast/online_response.py:37–153  ·  view source on GitHub ↗

Defines an online response in feast.

Source from the content-addressed store, hash-verified

35
36
37class 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:

Calls

no outgoing calls

Tested by 4

builderFunction · 0.72
builderMethod · 0.72