Skip to content

Commit 4777c03

Browse files
nanohannohkuepers
andauthored
feat: Add Decimal to allowed python scalar types (#5367)
Add Decimal to allowed python scalar types Signed-off-by: hkuepers <hanno.kuepers@ratepay.com> Co-authored-by: hkuepers <hanno.kuepers@ratepay.com>
1 parent 648c53d commit 4777c03

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

sdk/python/feast/type_map.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import decimal
1516
import json
1617
import logging
1718
from collections import defaultdict
@@ -310,7 +311,11 @@ def _type_err(item, dtype):
310311
None,
311312
),
312313
ValueType.FLOAT: ("float_val", lambda x: float(x), None),
313-
ValueType.DOUBLE: ("double_val", lambda x: x, {float, np.float64, int, np.int_}),
314+
ValueType.DOUBLE: (
315+
"double_val",
316+
lambda x: x,
317+
{float, np.float64, int, np.int_, decimal.Decimal},
318+
),
314319
ValueType.STRING: ("string_val", lambda x: str(x), None),
315320
ValueType.BYTES: ("bytes_val", lambda x: x, {bytes}),
316321
ValueType.BOOL: ("bool_val", lambda x: x, {bool, np.bool_, int, np.int_}),
@@ -457,7 +462,7 @@ def _python_value_to_proto_value(
457462
if (sample == 0 or sample == 0.0) and feast_value_type != ValueType.BOOL:
458463
# Numpy convert 0 to int. However, in the feature view definition, the type of column may be a float.
459464
# So, if value is 0, type validation must pass if scalar_types are either int or float.
460-
allowed_types = {np.int64, int, np.float64, float}
465+
allowed_types = {np.int64, int, np.float64, float, decimal.Decimal}
461466
assert type(sample) in allowed_types, (
462467
f"Type `{type(sample)}` not in {allowed_types}"
463468
)

0 commit comments

Comments
 (0)