From 422874ed440e44e8c16230a5771aec1db1d97fa2 Mon Sep 17 00:00:00 2001 From: Bhargav Dodla Date: Fri, 2 Aug 2024 16:07:13 -0700 Subject: [PATCH] fix: Null value compatibility for unit timestamp list value type Signed-off-by: Bhargav Dodla --- sdk/python/feast/type_map.py | 17 +++++++++++------ sdk/python/tests/unit/test_type_map.py | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/sdk/python/feast/type_map.py b/sdk/python/feast/type_map.py index 4e9b54c631..e47e4fcbe4 100644 --- a/sdk/python/feast/type_map.py +++ b/sdk/python/feast/type_map.py @@ -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_. diff --git a/sdk/python/tests/unit/test_type_map.py b/sdk/python/tests/unit/test_type_map.py index 39e3e7dafa..be8a25c163 100644 --- a/sdk/python/tests/unit/test_type_map.py +++ b/sdk/python/tests/unit/test_type_map.py @@ -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]),