File tree Expand file tree Collapse file tree 2 files changed +42
-2
lines changed
Expand file tree Collapse file tree 2 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 4646from feast .protos .feast .types .Value_pb2 import Value as ProtoValue
4747from feast .value_type import ListType , ValueType
4848
49+ # null timestamps get converted to -9223372036854775808
50+ NULL_TIMESTAMP_INT_VALUE = np .datetime64 ("NaT" ).astype (int )
51+
4952
5053def feast_value_type_to_python_type (field_value_proto : ProtoValue ) -> Any :
5154 """
@@ -69,9 +72,18 @@ def feast_value_type_to_python_type(field_value_proto: ProtoValue) -> Any:
6972
7073 # Convert UNIX_TIMESTAMP values to `datetime`
7174 if val_attr == "unix_timestamp_list_val" :
72- val = [datetime .fromtimestamp (v , tz = timezone .utc ) for v in val ]
75+ val = [
76+ datetime .fromtimestamp (v , tz = timezone .utc )
77+ if v != NULL_TIMESTAMP_INT_VALUE
78+ else None
79+ for v in val
80+ ]
7381 elif val_attr == "unix_timestamp_val" :
74- val = datetime .fromtimestamp (val , tz = timezone .utc )
82+ val = (
83+ datetime .fromtimestamp (val , tz = timezone .utc )
84+ if val != NULL_TIMESTAMP_INT_VALUE
85+ else None
86+ )
7587
7688 return val
7789
Original file line number Diff line number Diff line change 1+ import numpy as np
2+
3+ from feast .type_map import (
4+ feast_value_type_to_python_type ,
5+ python_values_to_proto_values ,
6+ )
7+ from feast .value_type import ValueType
8+
9+
10+ def test_null_unix_timestamp ():
11+ """Test that null UnixTimestamps get converted from proto correctly."""
12+
13+ data = np .array (["NaT" ], dtype = "datetime64" )
14+ protos = python_values_to_proto_values (data , ValueType .UNIX_TIMESTAMP )
15+ converted = feast_value_type_to_python_type (protos [0 ])
16+
17+ assert converted is None
18+
19+
20+ def test_null_unix_timestamp_list ():
21+ """Test that UnixTimestamp lists with a null get converted from proto
22+ correctly."""
23+
24+ data = np .array ([["NaT" ]], dtype = "datetime64" )
25+ protos = python_values_to_proto_values (data , ValueType .UNIX_TIMESTAMP_LIST )
26+ converted = feast_value_type_to_python_type (protos [0 ])
27+
28+ assert converted [0 ] is None
You can’t perform that action at this time.
0 commit comments