Skip to content

Commit

Permalink
Test nans_to_nulls in pylibcudf
Browse files Browse the repository at this point in the history
  • Loading branch information
wence- committed Jul 12, 2024
1 parent 15802e6 commit cb2a5a4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
11 changes: 10 additions & 1 deletion python/cudf/cudf/pylibcudf_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ def sorted_opt(request):
return request.param


@pytest.fixture(scope="session", params=[False, True])
@pytest.fixture(
scope="session", params=[False, True], ids=["without_nulls", "with_nulls"]
)
def has_nulls(request):
return request.param


@pytest.fixture(
scope="session", params=[False, True], ids=["without_nans", "with_nans"]
)
def has_nans(request):
return request.param
32 changes: 32 additions & 0 deletions python/cudf/cudf/pylibcudf_tests/test_transform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2024, NVIDIA CORPORATION.

import math

import pyarrow as pa
from utils import assert_column_eq

from cudf._lib import pylibcudf as plc


def test_nans_to_nulls(has_nans):
if has_nans:
values = [1, float("nan"), float("nan"), None, 3, None]
else:
values = [1, 4, 5, None, 3, None]

replaced = [
None if (v is None or (v is not None and math.isnan(v))) else v
for v in values
]

h_input = pa.array(values, type=pa.float32())
input = plc.interop.from_arrow(h_input)
assert input.null_count() == h_input.null_count
expect = pa.array(replaced, type=pa.float32())

mask, null_count = plc.transform.nans_to_nulls(input)

assert null_count == expect.null_count
got = input.with_mask(mask, null_count)

assert_column_eq(expect, got)

0 comments on commit cb2a5a4

Please sign in to comment.