Skip to content

Commit

Permalink
Add basic tests of dataframe scan
Browse files Browse the repository at this point in the history
Also assert that unsupported file scan operations raise.
  • Loading branch information
wence- committed Jun 12, 2024
1 parent c0c2ad3 commit c2f207d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
43 changes: 43 additions & 0 deletions python/cudf_polars/tests/test_dataframescan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 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(
"subset",
[
None,
["a", "c"],
["b", "c", "d"],
["b", "d"],
["b", "c"],
["c", "e"],
["d", "e"],
pl.selectors.string(),
pl.selectors.integer(),
],
)
@pytest.mark.parametrize("predicate_pushdown", [False, True])
def test_scan_drop_nulls(subset, predicate_pushdown):
df = pl.LazyFrame(
{
"a": [1, 2, 3, 4],
"b": [None, 4, 5, None],
"c": [6, 7, None, None],
"d": [8, None, 9, 10],
"e": [None, None, "A", None],
}
)
# Drop nulls are pushed into filters
q = df.drop_nulls(subset)

assert_gpu_result_equal(
q, collect_kwargs={"predicate_pushdown": predicate_pushdown}
)
10 changes: 10 additions & 0 deletions python/cudf_polars/tests/test_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import polars as pl

from cudf_polars import translate_ir
from cudf_polars.testing.asserts import assert_gpu_result_equal


Expand Down Expand Up @@ -86,3 +87,12 @@ def test_scan(df, columns, mask):
if columns is not None:
q = df.select(*columns)
assert_gpu_result_equal(q)


def test_scan_unsupported_raises(tmp_path):
df = pl.DataFrame({"a": [1, 2, 3]})

df.write_ndjson(tmp_path / "df.json")
q = pl.scan_ndjson(tmp_path / "df.json")
with pytest.raises(NotImplementedError):
_ = translate_ir(q._ldf.visit())

0 comments on commit c2f207d

Please sign in to comment.