Skip to content

Commit

Permalink
Return UNIX_TIMESTAMP types as datetime to user
Browse files Browse the repository at this point in the history
Signed-off-by: Judah Rand <17158624+judahrand@users.noreply.github.com>
  • Loading branch information
judahrand committed Jan 27, 2022
1 parent 15d33a8 commit 0f7f9b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions sdk/python/feast/type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import re
from datetime import datetime, timezone
from typing import Any, Dict, List, Optional, Sequence, Set, Sized, Tuple, Type, cast

import numpy as np
Expand Down Expand Up @@ -49,8 +50,17 @@ def feast_value_type_to_python_type(field_value_proto: ProtoValue) -> Any:
if val_attr is None:
return None
val = getattr(field_value_proto, val_attr)

# If it's a _LIST type extract the list.
if hasattr(val, "val"):
val = list(val.val)

# Convert UNIX_TIMESTAMP values to `datetime`
if val_attr == "unix_timestamp_list_val":
val = [datetime.fromtimestamp(v, tz=timezone.utc) for v in val]
elif val_attr == "unix_timestamp_val":
val = datetime.fromtimestamp(val, tz=timezone.utc)

return val


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def test_feature_get_online_features_types_match(online_types_test_fixtures):
"float": float,
"string": str,
"bool": bool,
"datetime": int,
"datetime": datetime,
}
expected_dtype = feature_list_dtype_to_expected_online_response_value_type[
config.feature_dtype
Expand Down

0 comments on commit 0f7f9b2

Please sign in to comment.