From 619f6c930b3a32e2a37f9504a10e9c6239d5a82d Mon Sep 17 00:00:00 2001 From: "zlatan.el" Date: Mon, 19 Dec 2022 18:16:35 +0900 Subject: [PATCH 1/4] fix: Add assertion condition when value is 0 Signed-off-by: zlatan.el --- sdk/python/feast/type_map.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sdk/python/feast/type_map.py b/sdk/python/feast/type_map.py index 48da7c9acf..af37989d41 100644 --- a/sdk/python/feast/type_map.py +++ b/sdk/python/feast/type_map.py @@ -402,7 +402,10 @@ def _python_value_to_proto_value( valid_scalar_types, ) = PYTHON_SCALAR_VALUE_TYPE_TO_PROTO_VALUE[feast_value_type] if valid_scalar_types: - assert type(sample) in valid_scalar_types + if sample == 0 or sample == 0.0: + assert type(sample) in [np.int64, np.float64, float, int] + else: + assert type(sample) in valid_scalar_types if feast_value_type == ValueType.BOOL: # ProtoValue does not support conversion of np.bool_ so we need to convert it to support np.bool_. return [ From e0c952f97b81af85720e4c467d3b30607b02e3c2 Mon Sep 17 00:00:00 2001 From: "zlatan.el" Date: Mon, 19 Dec 2022 21:04:30 +0900 Subject: [PATCH 2/4] chore: Add comment about zero value validation Signed-off-by: zlatan.el --- sdk/python/feast/type_map.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/python/feast/type_map.py b/sdk/python/feast/type_map.py index af37989d41..2ec204f658 100644 --- a/sdk/python/feast/type_map.py +++ b/sdk/python/feast/type_map.py @@ -403,6 +403,7 @@ def _python_value_to_proto_value( ) = PYTHON_SCALAR_VALUE_TYPE_TO_PROTO_VALUE[feast_value_type] if valid_scalar_types: if sample == 0 or sample == 0.0: + # In the case of a value of 0, type validation cannot be performed with only one int or float type. assert type(sample) in [np.int64, np.float64, float, int] else: assert type(sample) in valid_scalar_types From 033a4325a9045074b72de9679423854faaeba3f4 Mon Sep 17 00:00:00 2001 From: "zlatan.el" Date: Mon, 19 Dec 2022 22:01:24 +0900 Subject: [PATCH 3/4] chore: Modifiy the comment Signed-off-by: zlatan.el --- sdk/python/feast/type_map.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/python/feast/type_map.py b/sdk/python/feast/type_map.py index 2ec204f658..04571f3369 100644 --- a/sdk/python/feast/type_map.py +++ b/sdk/python/feast/type_map.py @@ -403,7 +403,7 @@ def _python_value_to_proto_value( ) = PYTHON_SCALAR_VALUE_TYPE_TO_PROTO_VALUE[feast_value_type] if valid_scalar_types: if sample == 0 or sample == 0.0: - # In the case of a value of 0, type validation cannot be performed with only one int or float type. + # Numpy convert 0 to int. However, in the feature view definition, the type of column may be a float. assert type(sample) in [np.int64, np.float64, float, int] else: assert type(sample) in valid_scalar_types From 4b2fc9d766bcd27b487e9caf0697e235460724f2 Mon Sep 17 00:00:00 2001 From: "zlatan.el" Date: Mon, 19 Dec 2022 22:05:18 +0900 Subject: [PATCH 4/4] chore: Add the comment Signed-off-by: zlatan.el --- sdk/python/feast/type_map.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sdk/python/feast/type_map.py b/sdk/python/feast/type_map.py index 04571f3369..a91a6c141d 100644 --- a/sdk/python/feast/type_map.py +++ b/sdk/python/feast/type_map.py @@ -404,7 +404,8 @@ def _python_value_to_proto_value( if valid_scalar_types: if sample == 0 or sample == 0.0: # Numpy convert 0 to int. However, in the feature view definition, the type of column may be a float. - assert type(sample) in [np.int64, np.float64, float, int] + # So, if value is 0, type validation must pass if scalar_types are either int or float. + assert type(sample) in [np.int64, int, np.float64, float] else: assert type(sample) in valid_scalar_types if feast_value_type == ValueType.BOOL: