Skip to content

Commit a4e7d12

Browse files
arpitjain099claude
authored andcommitted
fix: Keep nulls in JSON-encoded array columns
Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
1 parent b6a3f3c commit a4e7d12

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎sdk/python/feast/type_map.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,13 +1029,20 @@ def _convert_list_values_to_proto(
10291029

10301030
json_sample = json.loads(sample)
10311031
if isinstance(json_sample, list):
1032-
json_values = [json.loads(value) for value in values]
1032+
json_values = [
1033+
json.loads(value) if value is not None else None for value in values
1034+
]
10331035
if feast_value_type == ValueType.BOOL_LIST:
10341036
json_values = [
1035-
[bool(item) for item in list_item] for list_item in json_values
1037+
[bool(item) for item in list_item]
1038+
if list_item is not None
1039+
else None
1040+
for list_item in json_values
10361041
]
10371042
return [
10381043
ProtoValue(**{field_name: proto_type(val=v)}) # type: ignore[arg-type]
1044+
if v is not None
1045+
else ProtoValue()
10391046
for v in json_values
10401047
]
10411048
raise _type_err(sample, valid_types[0])

‎sdk/python/tests/unit/test_type_map.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,25 @@ def test_python_values_to_proto_values_binary(value_type):
175175
assert feast_value_type_to_python_type(protos[1]) is None
176176

177177

178+
@pytest.mark.parametrize(
179+
"values, value_type, expected",
180+
(
181+
([b"[1,2]", None, b"[3]"], ValueType.INT64_LIST, [[1, 2], None, [3]]),
182+
([b"[1,2]", None, b"[3]"], ValueType.INT32_LIST, [[1, 2], None, [3]]),
183+
([b"[1.5]", None], ValueType.DOUBLE_LIST, [[1.5], None]),
184+
([b"[1.5]", None], ValueType.FLOAT_LIST, [[1.5], None]),
185+
([b'["a"]', None], ValueType.STRING_LIST, [["a"], None]),
186+
([b"[true,false]", None], ValueType.BOOL_LIST, [[True, False], None]),
187+
),
188+
)
189+
def test_python_values_to_proto_values_bytes_to_list_with_null(
190+
values, value_type, expected
191+
):
192+
"""A JSON-encoded array column keeps its nulls, as the set path already does."""
193+
protos = python_values_to_proto_values(values, value_type)
194+
assert [feast_value_type_to_python_type(proto) for proto in protos] == expected
195+
196+
178197
def test_python_values_to_proto_values_bytes_to_list_not_supported():
179198
with pytest.raises(TypeError):
180199
_ = python_values_to_proto_values([b"[]"], ValueType.BYTES_LIST)

0 commit comments

Comments
 (0)