Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick fixes for type map conversion issues related to empty lists #1846

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions sdk/python/feast/type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,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. "
Expand Down Expand Up @@ -257,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 is not None
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)


Expand Down