forked from rapidsai/cudf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Ternary copy_if_else (rapidsai#16114)
A straightforward evaluation using `copy_if_else`. Authors: - Lawrence Mitchell (https://github.com/wence-) Approvers: - https://github.com/brandon-b-miller URL: rapidsai#16114
- Loading branch information
Showing
3 changed files
with
66 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
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,27 @@ | ||
# 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 | ||
|
||
|
||
@pytest.mark.parametrize("then_scalar", [False, True]) | ||
@pytest.mark.parametrize("otherwise_scalar", [False, True]) | ||
@pytest.mark.parametrize("expr", [pl.col("c"), pl.col("c").is_not_null()]) | ||
def test_when_then(then_scalar, otherwise_scalar, expr): | ||
ldf = pl.LazyFrame( | ||
{ | ||
"a": [1, 2, 3, 4, 5, 6, 7], | ||
"b": [10, 13, 11, 15, 16, 11, 10], | ||
"c": [None, True, False, False, True, True, False], | ||
} | ||
) | ||
|
||
then = pl.lit(10) if then_scalar else pl.col("a") | ||
otherwise = pl.lit(-2) if otherwise_scalar else pl.col("b") | ||
q = ldf.select(pl.when(expr).then(then).otherwise(otherwise)) | ||
assert_gpu_result_equal(q) |