|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -import base64 |
16 | 15 | import re |
17 | 16 | from datetime import datetime |
18 | 17 | from typing import Any, Dict, List, Optional, Set, Tuple, Type |
19 | 18 |
|
20 | 19 | import numpy as np |
21 | 20 | import pandas as pd |
22 | 21 | import pyarrow |
23 | | -from google.protobuf.json_format import MessageToDict |
24 | 22 | from google.protobuf.pyext.cpp_message import GeneratedProtocolMessageType |
25 | 23 | from google.protobuf.timestamp_pb2 import Timestamp |
26 | 24 |
|
@@ -48,44 +46,13 @@ def feast_value_type_to_python_type(field_value_proto: ProtoValue) -> Any: |
48 | 46 | Returns: |
49 | 47 | Python native type representation/version of the given field_value_proto |
50 | 48 | """ |
51 | | - field_value_dict = MessageToDict(field_value_proto, float_precision=18) # type: ignore |
52 | | - |
53 | | - # This can happen when proto_json.patch() has been called before this call, which is true for a feature server |
54 | | - if not isinstance(field_value_dict, dict): |
55 | | - return field_value_dict |
56 | | - |
57 | | - for k, v in field_value_dict.items(): |
58 | | - if "List" in k: |
59 | | - val = v.get("val", []) |
60 | | - else: |
61 | | - val = v |
62 | | - |
63 | | - if k == "int64Val": |
64 | | - return int(val) |
65 | | - if k == "bytesVal": |
66 | | - # MessageToDict converts the bytes object to base64 encoded string: |
67 | | - # https://developers.google.com/protocol-buffers/docs/proto3#json |
68 | | - return base64.b64decode(val) |
69 | | - if (k == "int64ListVal") or (k == "int32ListVal"): |
70 | | - return [int(item) for item in val] |
71 | | - if (k == "floatListVal") or (k == "doubleListVal"): |
72 | | - return [float(item) for item in val] |
73 | | - if k == "stringListVal": |
74 | | - return [str(item) for item in val] |
75 | | - if k == "bytesListVal": |
76 | | - # MessageToDict converts the bytes object to base64 encoded string: |
77 | | - # https://developers.google.com/protocol-buffers/docs/proto3#json |
78 | | - return [base64.b64decode(val) for item in val] |
79 | | - if k == "boolListVal": |
80 | | - return [bool(item) for item in val] |
81 | | - |
82 | | - if k in ["int32Val", "floatVal", "doubleVal", "stringVal", "boolVal"]: |
83 | | - return val |
84 | | - else: |
85 | | - raise TypeError( |
86 | | - f"Casting to Python native type for type {k} failed. " |
87 | | - f"Type {k} not found" |
88 | | - ) |
| 49 | + val_attr = field_value_proto.WhichOneof("val") |
| 50 | + if val_attr is None: |
| 51 | + return None |
| 52 | + val = getattr(field_value_proto, val_attr) |
| 53 | + if hasattr(val, "val"): |
| 54 | + val = list(val.val) |
| 55 | + return val |
89 | 56 |
|
90 | 57 |
|
91 | 58 | def feast_value_type_to_pandas_type(value_type: ValueType) -> Any: |
|
0 commit comments