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

Require fixed width types for casting in cudf-polars #16381

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion python/cudf_polars/cudf_polars/dsl/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,11 @@ class Cast(Expr):
def __init__(self, dtype: plc.DataType, value: Expr) -> None:
super().__init__(dtype)
self.children = (value,)
if not plc.unary.is_supported_cast(self.dtype, value.dtype):
if (
not plc.traits.is_fixed_width(self.dtype)
and plc.traits.is_fixed_width(value.dtype)
vyasr marked this conversation as resolved.
Show resolved Hide resolved
and plc.unary.is_supported_cast(self.dtype, value.dtype)
):
raise NotImplementedError(
f"Can't cast {self.dtype.id().name} to {value.dtype.id().name}"
)
Expand Down
14 changes: 13 additions & 1 deletion python/cudf_polars/tests/expressions/test_numeric_binops.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

import polars as pl

from cudf_polars.testing.asserts import assert_gpu_result_equal
from cudf_polars.testing.asserts import (
assert_gpu_result_equal,
assert_ir_translation_raises,
)

dtypes = [
pl.Int8,
Expand Down Expand Up @@ -111,3 +114,12 @@ def test_binop_with_scalar(left_scalar, right_scalar):
q = df.select(lop / rop)

assert_gpu_result_equal(q)


def test_numeric_to_string_cast_fails():
df = pl.DataFrame(
{"a": [1, 1, 2, 3, 3, 4, 1], "b": [None, 2, 3, 4, 5, 6, 7]}
).lazy()
q = df.select(pl.col("a").cast(pl.String))

assert_ir_translation_raises(q, NotImplementedError)
Loading