FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: Correctly handle list values in _python_value_to_proto_value by TBourtonBumble · Pull Request #4608 · feast-dev/feast · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
24 changes: 19 additions & 5 deletions sdk/python/feast/type_map.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Any chance you can add a test here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Back | FazBrowse Home | New Git URL