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

fix: Correctly handle list values in _python_value_to_proto_value #4608

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 19 additions & 5 deletions sdk/python/feast/type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,18 @@ def _python_value_to_proto_value(
if feast_value_type == ValueType.BYTES_LIST:
raise _type_err(sample, ValueType.BYTES_LIST)

json_value = json.loads(sample)
if isinstance(json_value, list):
json_sample = json.loads(sample)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance you can add a test here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sure thing. Did you have in mind something to check that json.loads(sample) does not error out? E.g. if there's something like a json decode error?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it's fine. There's no test there currently so no need to add additional work here. Thank you!

if isinstance(json_sample, list):
json_values = [json.loads(value) for value in values]
if feast_value_type == ValueType.BOOL_LIST:
json_value = [bool(item) for item in json_value]
return [ProtoValue(**{field_name: proto_type(val=json_value)})] # type: ignore
json_values = [
[bool(item) for item in list_item]
for list_item in json_values
]
return [
ProtoValue(**{field_name: proto_type(val=v)}) # type: ignore
for v in json_values
]
raise _type_err(sample, valid_types[0])

if sample is not None and not all(
Expand Down Expand Up @@ -506,7 +513,14 @@ def python_values_to_proto_values(
if value_type == ValueType.UNKNOWN:
raise TypeError("Couldn't infer value type from empty value")

return _python_value_to_proto_value(value_type, values)
proto_values = _python_value_to_proto_value(value_type, values)

if len(proto_values) != len(values):
raise ValueError(
f"Number of proto values {len(proto_values)} does not match number of values {len(values)}"
)

return proto_values


def _proto_value_to_value_type(proto_value: ProtoValue) -> ValueType:
Expand Down
Loading