-
Notifications
You must be signed in to change notification settings - Fork 901
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fall back when casting a timestamp to numeric in cudf-polars (#16232)
This PR adds logic that falls back to CPU when a cudf-polars query would cast a timestamp column to a numeric type, an unsupported operation in libcudf, which should fix a few polars tests. It could be cleaned up a bit with some of the utilities that will be added in #16150. Authors: - https://github.com/brandon-b-miller Approvers: - Lawrence Mitchell (https://github.com/wence-) URL: #16232
- Loading branch information
1 parent
c7b28ce
commit e6d412c
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |