Skip to content

Commit

Permalink
Merge branch 'branch-24.08' of github.com:rapidsai/cudf into pylibcud…
Browse files Browse the repository at this point in the history
…f-io-writers
  • Loading branch information
lithomas1 committed Jun 12, 2024
2 parents 8c4c4e4 + b35991c commit 63358e9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion python/cudf_polars/cudf_polars/dsl/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ def do_evaluate(
obj = plc.replace.replace_nulls(
indices.obj,
plc.interop.from_arrow(
pa.scalar(n, type=plc.interop.to_arrow(indices.obj.data_type()))
pa.scalar(n, type=plc.interop.to_arrow(indices.obj.type()))
),
)
else:
Expand Down
4 changes: 2 additions & 2 deletions python/cudf_polars/cudf_polars/dsl/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,10 +933,10 @@ class Union(IR):
"""Optional slice to apply after concatenation."""

def __post_init__(self) -> None:
"""Validated preconditions."""
"""Validate preconditions."""
schema = self.dfs[0].schema
if not all(s.schema == schema for s in self.dfs[1:]):
raise ValueError("Schema mismatch")
raise NotImplementedError("Schema mismatch")

def evaluate(self, *, cache: MutableMapping[int, DataFrame]) -> DataFrame:
"""Evaluate and return a dataframe."""
Expand Down
31 changes: 31 additions & 0 deletions python/cudf_polars/tests/expressions/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

import pytest

import polars as pl

from cudf_polars import execute_with_cudf
from cudf_polars.testing.asserts import assert_gpu_result_equal


Expand All @@ -17,3 +20,31 @@ def test_gather():

query = ldf.select(pl.col("a").gather(pl.col("b")))
assert_gpu_result_equal(query)


def test_gather_with_nulls():
ldf = pl.LazyFrame(
{
"a": [1, 2, 3, 4, 5, 6, 7],
"b": [0, None, 1, None, 6, 1, 0],
}
)

query = ldf.select(pl.col("a").gather(pl.col("b")))

assert_gpu_result_equal(query)


@pytest.mark.parametrize("negative", [False, True])
def test_gather_out_of_bounds(negative):
ldf = pl.LazyFrame(
{
"a": [1, 2, 3, 4, 5, 6, 7],
"b": [0, -10 if negative else 10, 1, 2, 6, 1, 0],
}
)

query = ldf.select(pl.col("a").gather(pl.col("b")))

with pytest.raises(pl.exceptions.ComputeError):
query.collect(post_opt_callback=execute_with_cudf)
16 changes: 16 additions & 0 deletions python/cudf_polars/tests/test_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations

import pytest

import polars as pl

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


Expand All @@ -19,6 +22,19 @@ def test_union():
assert_gpu_result_equal(query)


def test_union_schema_mismatch_raises():
ldf = pl.DataFrame(
{
"a": [1, 2, 3, 4, 5, 6, 7],
"b": [1, 1, 1, 1, 1, 1, 1],
}
).lazy()
ldf2 = ldf.select(pl.col("a").cast(pl.Float32))
query = pl.concat([ldf, ldf2], how="diagonal")
with pytest.raises(NotImplementedError):
_ = translate_ir(query._ldf.visit())


def test_concat_vertical():
ldf = pl.LazyFrame(
{
Expand Down

0 comments on commit 63358e9

Please sign in to comment.