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

Fall back when casting a timestamp to numeric in cudf-polars #16232

4 changes: 4 additions & 0 deletions python/cudf_polars/cudf_polars/dsl/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,10 @@ 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):
raise NotImplementedError(
f"Can't cast {self.dtype.id().name} to {value.dtype.id().name}"
)
Comment on lines +1164 to +1166
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test this branch please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a2858e6 should cover things


def do_evaluate(
self,
Expand Down
52 changes: 52 additions & 0 deletions python/cudf_polars/tests/expressions/test_casting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

import pytest

import polars as pl

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

_supported_dtypes = [(pl.Int8(), pl.Int64())]

_unsupported_dtypes = [
(pl.String(), pl.Int64()),
]


@pytest.fixture
def dtypes(request):
return request.param


@pytest.fixture
def tests(dtypes):
fromtype, totype = dtypes
if fromtype == pl.String():
data = ["a", "b", "c"]
else:
data = [1, 2, 3]
return pl.DataFrame(
{
"a": pl.Series(data, dtype=fromtype),
}
).lazy(), totype


@pytest.mark.parametrize("dtypes", _supported_dtypes, indirect=True)
def test_cast_supported(tests):
df, totype = tests
q = df.select(pl.col("a").cast(totype))
assert_gpu_result_equal(q)


@pytest.mark.parametrize("dtypes", _unsupported_dtypes, indirect=True)
def test_cast_unsupported(tests):
df, totype = tests
assert_ir_translation_raises(
df.select(pl.col("a").cast(totype)), NotImplementedError
)
Loading