Skip to content

Commit fda77d5

Browse files
committed
Fix datetime features in type_map.py
Signed-off-by: Judah Rand <17158624+judahrand@users.noreply.github.com>
1 parent 49cd611 commit fda77d5

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎sdk/python/feast/type_map.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def _type_err(item, dtype):
212212
ValueType.UNIX_TIMESTAMP_LIST: (
213213
Int64List,
214214
"int64_list_val",
215-
[np.int64, np.int32, int],
215+
[np.datetime64, np.int64, np.int32, int, datetime, Timestamp],
216216
),
217217
ValueType.STRING_LIST: (StringList, "string_list_val", [np.str_, str]),
218218
ValueType.BOOL_LIST: (BoolList, "bool_list_val", [np.bool_, bool]),
@@ -272,6 +272,24 @@ def _python_value_to_proto_value(
272272
)
273273
raise _type_err(first_invalid, valid_types[0])
274274

275+
if feast_value_type == ValueType.UNIX_TIMESTAMP_LIST:
276+
converted_values = []
277+
for value in values:
278+
converted_sub_values = []
279+
for sub_value in value:
280+
if isinstance(sub_value, datetime):
281+
converted_sub_values.append(int(sub_value.timestamp()))
282+
elif isinstance(sub_value, Timestamp):
283+
converted_sub_values.append(int(sub_value.ToSeconds()))
284+
elif isinstance(sub_value, np.datetime64):
285+
converted_sub_values.append(
286+
sub_value.astype("datetime64[s]").astype("int")
287+
)
288+
else:
289+
converted_sub_values.append(sub_value)
290+
converted_values.append(converted_sub_values)
291+
values = converted_values
292+
275293
return [
276294
ProtoValue(**{field_name: proto_type(val=value)})
277295
if value is not None

0 commit comments

Comments
 (0)