-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #16219 Authors: - https://github.com/brandon-b-miller Approvers: - Lawrence Mitchell (https://github.com/wence-) URL: #16290
- Loading branch information
1 parent
0cac2a9
commit c7b28ce
Showing
2 changed files
with
94 additions
and
1 deletion.
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,65 @@ | ||
# 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, | ||
) | ||
|
||
|
||
@pytest.fixture( | ||
params=[ | ||
[1, 2, 1, 3, 5, None, None], | ||
[1.5, 2.5, None, 1.5, 3, float("nan"), 3], | ||
[], | ||
[None, None], | ||
[1, 2, 3, 4, 5], | ||
] | ||
) | ||
def null_data(request): | ||
is_empty = pl.Series(request.param).dtype == pl.Null | ||
return pl.DataFrame( | ||
{ | ||
"a": pl.Series(request.param, dtype=pl.Float64 if is_empty else None), | ||
"b": pl.Series(request.param, dtype=pl.Float64 if is_empty else None), | ||
} | ||
).lazy() | ||
|
||
|
||
def test_drop_null(null_data): | ||
q = null_data.select(pl.col("a").drop_nulls()) | ||
assert_gpu_result_equal(q) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"value", | ||
[0, pl.col("a").mean(), pl.col("b")], | ||
ids=["scalar", "aggregation", "column_expression"], | ||
) | ||
def test_fill_null(null_data, value): | ||
q = null_data.select(pl.col("a").fill_null(value)) | ||
assert_gpu_result_equal(q) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"strategy", ["forward", "backward", "min", "max", "mean", "zero", "one"] | ||
) | ||
def test_fill_null_with_strategy(null_data, strategy): | ||
q = null_data.select(pl.col("a").fill_null(strategy=strategy)) | ||
|
||
# Not yet exposed to python from rust | ||
assert_ir_translation_raises(q, NotImplementedError) | ||
|
||
|
||
@pytest.mark.parametrize("strategy", ["forward", "backward"]) | ||
@pytest.mark.parametrize("limit", [0, 1, 2]) | ||
def test_fill_null_with_limit(null_data, strategy, limit): | ||
q = null_data.select(pl.col("a").fill_null(strategy=strategy, limit=limit)) | ||
|
||
# Not yet exposed to python from rust | ||
assert_ir_translation_raises(q, NotImplementedError) |