From 5e5c5ebaa3ee27ced9654403f4b8d21fed9ca1ae Mon Sep 17 00:00:00 2001 From: Neil Johnson Date: Fri, 10 Nov 2023 14:31:01 +0000 Subject: [PATCH] fix: Cast should treat nullable and non-nullables as the same (#1037) --- third_party/ibis/ibis_addon/api.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/third_party/ibis/ibis_addon/api.py b/third_party/ibis/ibis_addon/api.py index e34375c04..4e1ab9fa2 100644 --- a/third_party/ibis/ibis_addon/api.py +++ b/third_party/ibis/ibis_addon/api.py @@ -23,10 +23,19 @@ def cast(self, target_type: dt.DataType) -> Value: """Override ibis.expr.api's cast method. This allows for Timestamp-typed columns to be cast to Timestamp, since Ibis interprets some similar but non-equivalent types (eg. DateTime) to Timestamp (GitHub issue #451). """ + + def same_type(from_type, to_type) -> bool: + # The data type for Non-nullable columns if prefixed with "!", this is causing deviations + # between nullable and non-nullable columns. The second comparison below is catering for this. + return bool( + from_type == to_type + or str(from_type).lstrip("!") == str(to_type).lstrip("!") + ) + # validate op = ops.Cast(self, to=target_type) - if op.to == self.type() and not op.to.is_timestamp(): + if same_type(op.to, self.type()) and not op.to.is_timestamp(): # noop case if passed type is the same return self