Skip to content

Commit

Permalink
fix: Null value compatibility for unit timestamp list value type
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhargav Dodla committed Aug 2, 2024
1 parent 67a63d9 commit f3f8aeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 11 additions & 6 deletions sdk/python/feast/type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,18 @@ def _python_value_to_proto_value(
raise _type_err(item, valid_types[0])

if feast_value_type == ValueType.UNIX_TIMESTAMP_LIST:
int_timestamps_lists = (
_python_datetime_to_int_timestamp(value) for value in values
)
return [
# ProtoValue does actually accept `np.int_` but the typing complains.
ProtoValue(unix_timestamp_list_val=Int64List(val=ts)) # type: ignore
for ts in int_timestamps_lists
(
# ProtoValue does actually accept `np.int_` but the typing complains.
ProtoValue(
unix_timestamp_list_val=Int64List(
val=_python_datetime_to_int_timestamp(value) # type: ignore
)
)
if value is not None
else ProtoValue()
)
for value in values
]
if feast_value_type == ValueType.BOOL_LIST:
# ProtoValue does not support conversion of np.bool_ so we need to convert it to support np.bool_.
Expand Down
7 changes: 7 additions & 0 deletions sdk/python/tests/unit/test_type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ def test_python_values_to_proto_values_bool(values):
(np.array([b'["a","b","c"]']), ValueType.STRING_LIST, ["a", "b", "c"]),
(np.array([b"[true,false]"]), ValueType.BOOL_LIST, [True, False]),
(np.array([b"[1,0]"]), ValueType.BOOL_LIST, [True, False]),
(np.array([None]), ValueType.INT32_LIST, None),
(np.array([None]), ValueType.INT64_LIST, None),
(np.array([None]), ValueType.FLOAT_LIST, None),
(np.array([None]), ValueType.DOUBLE_LIST, None),
(np.array([None]), ValueType.BOOL_LIST, None),
(np.array([None]), ValueType.BYTES_LIST, None),
(np.array([None]), ValueType.STRING_LIST, None),
(np.array([None]), ValueType.UNIX_TIMESTAMP_LIST, None),
([b"[1,2,3]"], ValueType.INT64_LIST, [1, 2, 3]),
([b"[1,2,3]"], ValueType.INT32_LIST, [1, 2, 3]),
([b"[1.5,2.5,3.5]"], ValueType.FLOAT_LIST, [1.5, 2.5, 3.5]),
Expand Down

0 comments on commit f3f8aeb

Please sign in to comment.