Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cast treats nullable and non-nullable columns in the same way #1037

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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