Skip to content

Commit c0db1c9

Browse files
authored
chore: Add tests to bool test type (#3473)
* chore(test): add tests to bool test type Signed-off-by: gbmarc1 <[email protected]> * style(isort): order pytest import Signed-off-by: gbmarc1 <[email protected]> --------- Signed-off-by: gbmarc1 <[email protected]>
1 parent bab6644 commit c0db1c9

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

sdk/python/feast/type_map.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def _type_err(item, dtype):
300300
ValueType.DOUBLE: ("double_val", lambda x: x, {float, np.float64}),
301301
ValueType.STRING: ("string_val", lambda x: str(x), None),
302302
ValueType.BYTES: ("bytes_val", lambda x: x, {bytes}),
303-
ValueType.BOOL: ("bool_val", lambda x: x, {bool, np.bool_}),
303+
ValueType.BOOL: ("bool_val", lambda x: x, {bool, np.bool_, int, np.int_}),
304304
}
305305

306306

@@ -405,9 +405,14 @@ def _python_value_to_proto_value(
405405
if (sample == 0 or sample == 0.0) and feast_value_type != ValueType.BOOL:
406406
# Numpy convert 0 to int. However, in the feature view definition, the type of column may be a float.
407407
# So, if value is 0, type validation must pass if scalar_types are either int or float.
408-
assert type(sample) in [np.int64, int, np.float64, float]
408+
allowed_types = {np.int64, int, np.float64, float}
409+
assert (
410+
type(sample) in allowed_types
411+
), f"Type `{type(sample)}` not in {allowed_types}"
409412
else:
410-
assert type(sample) in valid_scalar_types
413+
assert (
414+
type(sample) in valid_scalar_types
415+
), f"Type `{type(sample)}` not in {valid_scalar_types}"
411416
if feast_value_type == ValueType.BOOL:
412417
# ProtoValue does not support conversion of np.bool_ so we need to convert it to support np.bool_.
413418
return [

sdk/python/tests/unit/test_type_map.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
import pytest
23

34
from feast.type_map import (
45
feast_value_type_to_python_type,
@@ -26,3 +27,24 @@ def test_null_unix_timestamp_list():
2627
converted = feast_value_type_to_python_type(protos[0])
2728

2829
assert converted[0] is None
30+
31+
32+
@pytest.mark.parametrize(
33+
"values",
34+
(
35+
np.array([True]),
36+
np.array([False]),
37+
np.array([0]),
38+
np.array([1]),
39+
[True],
40+
[False],
41+
[0],
42+
[1],
43+
),
44+
)
45+
def test_python_values_to_proto_values_bool(values):
46+
47+
protos = python_values_to_proto_values(values, ValueType.BOOL)
48+
converted = feast_value_type_to_python_type(protos[0])
49+
50+
assert converted is bool(values[0])

0 commit comments

Comments
 (0)