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

Add coverage for both expression and dataframe filter #16002

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 23 additions & 7 deletions python/cudf_polars/tests/expressions/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,35 @@
# 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


def test_filter():
ldf = pl.DataFrame(
@pytest.mark.parametrize(
"expr",
[
pytest.param(
pl.lit(value=False),
marks=pytest.mark.xfail(reason="Expression filter does not handle scalars"),
),
pl.col("c"),
pl.col("b") > 2,
],
)
@pytest.mark.parametrize("predicate_pushdown", [False, True])
def test_filter_expression(expr, predicate_pushdown):
ldf = pl.LazyFrame(
{
"a": [1, 2, 3, 4, 5, 6, 7],
"b": [1, 1, 1, 1, 1, 1, 1],
"b": [0, 3, 1, 5, 6, 1, 0],
"c": [None, True, False, False, True, True, False],
}
).lazy()
)

# group-by is just to avoid the filter being pushed into the scan.
query = ldf.group_by(pl.col("a")).agg(pl.col("b").sum()).filter(pl.col("b") < 1)
assert_gpu_result_equal(query)
query = ldf.select(pl.col("a").filter(expr))
assert_gpu_result_equal(
query, collect_kwargs={"predicate_pushdown": predicate_pushdown}
)
26 changes: 26 additions & 0 deletions python/cudf_polars/tests/test_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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("expr", [pl.col("c"), pl.col("b") < 1, pl.lit(value=True)])
@pytest.mark.parametrize("predicate_pushdown", [False, True])
def test_filter(expr, predicate_pushdown):
ldf = pl.DataFrame(
{
"a": [1, 2, 3, 4, 5, 6, 7],
"b": [1, 1, 1, 1, 1, 1, 1],
"c": [True, False, False, True, True, True, None],
}
).lazy()

query = ldf.filter(expr)
assert_gpu_result_equal(
query, collect_kwargs={"predicate_pushdown": predicate_pushdown}
)
Loading