Skip to content

Commit 49cd611

Browse files
committed
Add datetime feature to tests
Signed-off-by: Judah Rand <17158624+judahrand@users.noreply.github.com>
1 parent 77af10f commit 49cd611

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

‎sdk/python/tests/data/data_creator.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def get_feature_values_for_dtype(
6060
"float": [1.0, None, 3.0, 4.0, 5.0],
6161
"string": ["1", None, "3", "4", "5"],
6262
"bool": [True, None, False, True, False],
63+
"datetime": [
64+
datetime(1980, 1, 1),
65+
None,
66+
datetime(1981, 1, 1),
67+
datetime(1982, 1, 1),
68+
datetime(1982, 1, 1),
69+
],
6370
}
6471
non_list_val = dtype_map[dtype]
6572
if is_list:

‎sdk/python/tests/integration/registration/test_universal_types.py‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import re
23
from dataclasses import dataclass
34
from datetime import datetime, timedelta
45
from typing import List
@@ -28,6 +29,7 @@ def populate_test_configs(offline: bool):
2829
(ValueType.INT64, "int64"),
2930
(ValueType.STRING, "float"),
3031
(ValueType.STRING, "bool"),
32+
(ValueType.INT32, "datetime"),
3133
]
3234
configs: List[TypeTestConfig] = []
3335
for test_repo_config in FULL_REPO_CONFIGS:
@@ -232,6 +234,7 @@ def test_feature_get_online_features_types_match(online_types_test_fixtures):
232234
"float": float,
233235
"string": str,
234236
"bool": bool,
237+
"datetime": int,
235238
}
236239
expected_dtype = feature_list_dtype_to_expected_online_response_value_type[
237240
config.feature_dtype
@@ -258,6 +261,8 @@ def create_feature_view(
258261
value_type = ValueType.FLOAT_LIST
259262
elif feature_dtype == "bool":
260263
value_type = ValueType.BOOL_LIST
264+
elif feature_dtype == "datetime":
265+
value_type = ValueType.UNIX_TIMESTAMP_LIST
261266
else:
262267
if feature_dtype == "int32":
263268
value_type = ValueType.INT32
@@ -267,6 +272,8 @@ def create_feature_view(
267272
value_type = ValueType.FLOAT
268273
elif feature_dtype == "bool":
269274
value_type = ValueType.BOOL
275+
elif feature_dtype == "datetime":
276+
value_type = ValueType.UNIX_TIMESTAMP
270277

271278
return driver_feature_view(data_source, name=name, value_type=value_type,)
272279

@@ -281,6 +288,7 @@ def assert_expected_historical_feature_types(
281288
"float": (pd.api.types.is_float_dtype,),
282289
"string": (pd.api.types.is_string_dtype,),
283290
"bool": (pd.api.types.is_bool_dtype, pd.api.types.is_object_dtype),
291+
"datetime": (pd.api.types.is_datetime64_any_dtype,),
284292
}
285293
dtype_checkers = feature_dtype_to_expected_historical_feature_dtype[feature_dtype]
286294
assert any(
@@ -307,6 +315,7 @@ def assert_feature_list_types(
307315
bool,
308316
np.bool_,
309317
), # Can be `np.bool_` if from `np.array` rather that `list`
318+
"datetime": np.datetime64,
310319
}
311320
expected_dtype = feature_list_dtype_to_expected_historical_feature_list_dtype[
312321
feature_dtype
@@ -328,22 +337,23 @@ def assert_expected_arrow_types(
328337
historical_features_arrow = historical_features.to_arrow()
329338
print(historical_features_arrow)
330339
feature_list_dtype_to_expected_historical_feature_arrow_type = {
331-
"int32": "int64",
332-
"int64": "int64",
333-
"float": "double",
334-
"string": "string",
335-
"bool": "bool",
340+
"int32": r"int64",
341+
"int64": r"int64",
342+
"float": r"double",
343+
"string": r"string",
344+
"bool": r"bool",
345+
"datetime": r"timestamp\[.+\]",
336346
}
337347
arrow_type = feature_list_dtype_to_expected_historical_feature_arrow_type[
338348
feature_dtype
339349
]
340350
if feature_is_list:
341-
assert (
342-
str(historical_features_arrow.schema.field_by_name("value").type)
343-
== f"list<item: {arrow_type}>"
351+
assert re.match(
352+
f"list<item: {arrow_type}>",
353+
str(historical_features_arrow.schema.field_by_name("value").type),
344354
)
345355
else:
346-
assert (
347-
str(historical_features_arrow.schema.field_by_name("value").type)
348-
== arrow_type
356+
assert re.match(
357+
arrow_type,
358+
str(historical_features_arrow.schema.field_by_name("value").type),
349359
)

0 commit comments

Comments
 (0)