From 2f3065059a062cbd426203e1ac2573b73f1ef266 Mon Sep 17 00:00:00 2001 From: Karl Higley Date: Mon, 14 Jun 2021 12:09:41 -0400 Subject: [PATCH 1/3] Fix materialization of features with integer list types --- sdk/python/feast/type_map.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/python/feast/type_map.py b/sdk/python/feast/type_map.py index 576a0b7f35..7e6ac388c7 100644 --- a/sdk/python/feast/type_map.py +++ b/sdk/python/feast/type_map.py @@ -235,7 +235,7 @@ def _python_value_to_proto_value(feast_value_type, value) -> ProtoValue: return ProtoValue( int32_list_val=Int32List( val=[ - item if type(item) is np.int32 else _type_err(item, np.int32) + item if type(item) in [np.int32, int] else _type_err(item, np.int32) for item in value ] ) @@ -246,7 +246,7 @@ def _python_value_to_proto_value(feast_value_type, value) -> ProtoValue: int64_list_val=Int64List( val=[ item - if type(item) in [np.int64, np.int32] + if type(item) in [np.int64, np.int32, int] else _type_err(item, np.int64) for item in value ] @@ -258,7 +258,7 @@ def _python_value_to_proto_value(feast_value_type, value) -> ProtoValue: int64_list_val=Int64List( val=[ item - if type(item) in [np.int64, np.int32] + if type(item) in [np.int64, np.int32, int] else _type_err(item, np.int64) for item in value ] From 018dcd271e3e9a6b2b1b0feb2a34e1883afd5acc Mon Sep 17 00:00:00 2001 From: Karl Higley Date: Wed, 8 Sep 2021 10:15:39 -0400 Subject: [PATCH 2/3] Fix conversion of Feast lists back to Python types --- sdk/python/feast/type_map.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/sdk/python/feast/type_map.py b/sdk/python/feast/type_map.py index 7e6ac388c7..6a582eab45 100644 --- a/sdk/python/feast/type_map.py +++ b/sdk/python/feast/type_map.py @@ -51,23 +51,28 @@ def feast_value_type_to_python_type(field_value_proto: ProtoValue) -> Any: field_value_dict = MessageToDict(field_value_proto) for k, v in field_value_dict.items(): + if "List" in k: + val = v.get("val", []) + else: + val = v + if k == "int64Val": - return int(v) + return int(val) if k == "bytesVal": - return bytes(v) + return bytes(val) if (k == "int64ListVal") or (k == "int32ListVal"): - return [int(item) for item in v["val"]] + return [int(item) for item in val] if (k == "floatListVal") or (k == "doubleListVal"): - return [float(item) for item in v["val"]] + return [float(item) for item in val] if k == "stringListVal": - return [str(item) for item in v["val"]] + return [str(item) for item in val] if k == "bytesListVal": - return [bytes(item) for item in v["val"]] + return [bytes(item) for item in val] if k == "boolListVal": - return [bool(item) for item in v["val"]] + return [bool(item) for item in val] if k in ["int32Val", "floatVal", "doubleVal", "stringVal", "boolVal"]: - return v + return val else: raise TypeError( f"Casting to Python native type for type {k} failed. " @@ -333,7 +338,7 @@ def python_value_to_proto_value( ) -> ProtoValue: value_type = ( python_type_to_feast_value_type("", value) - if value is not None + if value else feature_type ) return _python_value_to_proto_value(value_type, value) From 4ba31bf5904cfe6ed5d62b51975e714df4a1dd00 Mon Sep 17 00:00:00 2001 From: Karl Higley Date: Tue, 14 Sep 2021 10:52:57 -0400 Subject: [PATCH 3/3] Fix type map formatting --- sdk/python/feast/type_map.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sdk/python/feast/type_map.py b/sdk/python/feast/type_map.py index 3ecfaf5e66..461f172000 100644 --- a/sdk/python/feast/type_map.py +++ b/sdk/python/feast/type_map.py @@ -262,11 +262,7 @@ def _python_value_to_proto_value(feast_value_type, value) -> ProtoValue: def python_value_to_proto_value( value: Any, feature_type: ValueType = None ) -> ProtoValue: - value_type = ( - python_type_to_feast_value_type("", value) - if value - else feature_type - ) + value_type = python_type_to_feast_value_type("", value) if value else feature_type return _python_value_to_proto_value(value_type, value)