Skip to content

Commit

Permalink
fix: Cast should treat nullable and non-nullables as the same (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
nj1973 committed Nov 10, 2023
1 parent 48b0355 commit 5e5c5eb
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion third_party/ibis/ibis_addon/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5e5c5eb

Please sign in to comment.