From 703ca7522ef94641a333312b9fb8a34a827afaf3 Mon Sep 17 00:00:00 2001 From: Helen Cristina Date: Mon, 28 Aug 2023 11:43:06 -0300 Subject: [PATCH] fix: Add exception handling for invalid value to cast a comparison field (#957) * Add exception handling for invalid text for cast config parameter * fix: Adjust the exception handling message * Move and update exception handling --- third_party/ibis/ibis_addon/api.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/third_party/ibis/ibis_addon/api.py b/third_party/ibis/ibis_addon/api.py index b1c9cfe16..947a22854 100644 --- a/third_party/ibis/ibis_addon/api.py +++ b/third_party/ibis/ibis_addon/api.py @@ -14,6 +14,7 @@ import ibis.expr.datatypes as dt import ibis.expr.operations as ops +import parsy from ibis.expr.types.generic import Value @@ -42,8 +43,11 @@ def force_cast(self, target_type: dt.DataType) -> Value: """New method to force cast even if data type is the same. Used to cast a value to itself in ComparisonFields for nuances in data types i.e. casting CHAR to VARCHAR which are both Ibis strings """ - # validate - op = ops.Cast(self, to=target_type) + # validate target type + try: + op = ops.Cast(self, to=target_type) + except parsy.ParseError: + raise SyntaxError(f"'{target_type}' is an invalid datatype provided to cast a ComparisonField") if op.to.is_geospatial(): from_geotype = self.type().geotype or "geometry"