Skip to content
Open
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
19 changes: 0 additions & 19 deletions cpp/include/cudf/transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,25 +392,6 @@ std::unique_ptr<table> transform_lto(
cuda::stream_ref stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref());

/**
* @brief Creates a null_mask from `input` by converting `NaN` to null and
* preserving existing null values and also returns new null_count.
*
* @deprecated in release 26.04. Use column_nans_to_nulls instead.
*
* @throws cudf::logic_error if `input.type()` is a non-floating type
*
* @param input An immutable view of the input column of floating-point type
* @param stream CUDA stream used for device memory operations and kernel launches
* @param mr Device memory resource used to allocate the returned bitmask
* @return A pair containing a `device_buffer` with the new bitmask and its
* null count obtained by replacing `NaN` in `input` with null.
*/
[[deprecated]] std::pair<std::unique_ptr<rmm::device_buffer>, size_type> nans_to_nulls(
column_view const& input,
cuda::stream_ref stream = cudf::get_default_stream(),
rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref());

/**
* @brief Creates a null_mask from `input` by converting `NaN` elements to null rows
* and preserving existing null values
Expand Down
18 changes: 0 additions & 18 deletions cpp/src/transform/nans_to_nulls.cu
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ struct dispatch_nan_to_null {
}
};

std::pair<std::unique_ptr<rmm::device_buffer>, cudf::size_type> nans_to_nulls(
column_view const& input, cuda::stream_ref stream, rmm::device_async_resource_ref mr)
{
CUDF_EXPECTS(cudf::is_floating_point(input.type()),
"Input must be a floating point type",
std::invalid_argument);
if (input.is_empty()) { return std::pair(std::make_unique<rmm::device_buffer>(), 0); }

return cudf::type_dispatcher(input.type(), dispatch_nan_to_null{}, input, stream, mr);
}

struct copy_float_data_fn {
column_view const& input;
cuda::stream_ref stream;
Expand Down Expand Up @@ -107,13 +96,6 @@ std::unique_ptr<column> column_nans_to_nulls(column_view const& input,
}
} // namespace detail

std::pair<std::unique_ptr<rmm::device_buffer>, cudf::size_type> nans_to_nulls(
column_view const& input, cuda::stream_ref stream, rmm::device_async_resource_ref mr)
{
CUDF_FUNC_RANGE();
return detail::nans_to_nulls(input, stream, mr);
}

std::unique_ptr<column> column_nans_to_nulls(column_view const& input,
cuda::stream_ref stream,
rmm::device_async_resource_ref mr)
Expand Down
8 changes: 4 additions & 4 deletions python/cudf_polars/cudf_polars/containers/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,12 @@ def copy(self) -> Self:
)

def mask_nans(self, stream: Stream) -> Self:
"""Return a shallow copy of self with nans masked out."""
"""Return a copy of self with nans masked out."""
if plc.traits.is_floating_point(self.obj.type()):
old_count = self.null_count
mask, new_count = plc.transform.nans_to_nulls(self.obj, stream=stream)
result = type(self)(self.obj.with_mask(mask, new_count), self.dtype)
if old_count == new_count:
obj = plc.transform.column_nans_to_nulls(self.obj, stream=stream)
result = type(self)(obj, self.dtype)
if old_count == obj.null_count():
return result.sorted_like(self)
return result
return self.copy()
Expand Down
6 changes: 0 additions & 6 deletions python/pylibcudf/pylibcudf/libcudf/transform.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ cdef extern from "cudf/transform.hpp" namespace "cudf" nogil:
device_async_resource_ref mr
) except +libcudf_exception_handler

cdef pair[unique_ptr[device_buffer], size_type] nans_to_nulls(
const column_view& input,
cudaStream_t stream,
device_async_resource_ref mr
) except +libcudf_exception_handler

cdef unique_ptr[column] column_nans_to_nulls(
const column_view& input,
cudaStream_t stream,
Expand Down
4 changes: 0 additions & 4 deletions python/pylibcudf/pylibcudf/transform.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ from .table cimport Table
from .types cimport DataType


cpdef tuple[gpumemoryview, int] nans_to_nulls(
Column input, object stream = *, DeviceMemoryResource mr = *
)

cpdef Column column_nans_to_nulls(
Column input, object stream = *, DeviceMemoryResource mr = *
)
Expand Down
5 changes: 0 additions & 5 deletions python/pylibcudf/pylibcudf/transform.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ from pylibcudf.table import Table
from pylibcudf.types import DataType, NullAware, OutputNullability
from pylibcudf.utils import CudaStreamLike

def nans_to_nulls(
input: Column,
stream: CudaStreamLike | None = None,
mr: DeviceMemoryResource | None = None,
) -> tuple[gpumemoryview, int]: ...
def column_nans_to_nulls(
input: Column,
stream: CudaStreamLike | None = None,
Expand Down
42 changes: 0 additions & 42 deletions python/pylibcudf/pylibcudf/transform.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -48,52 +48,10 @@ __all__ = [
"compute_column_jit",
"encode",
"mask_to_bools",
"nans_to_nulls",
"one_hot_encode",
"transform",
]

cpdef tuple[gpumemoryview, int] nans_to_nulls(
Column input,
object stream: CudaStreamLike | None = None,
DeviceMemoryResource mr=None,
):
"""Create a null mask preserving existing nulls and converting nans to null.

For details, see :cpp:func:`nans_to_nulls`.

Parameters
----------
input : Column
Column to produce new mask from.
stream : Stream | None
CUDA stream on which to perform the operation.
mr : DeviceMemoryResource | None
Device memory resource used to allocate the returned mask's device memory.

Returns
-------
Two-tuple of a gpumemoryview wrapping the null mask and the new null count.
"""
cdef pair[unique_ptr[device_buffer], size_type] c_result

cdef Stream _stream = _get_stream(stream)
cdef cudaStream_t _cs = _stream.view().get()
mr = _get_memory_resource(mr)

cdef column_view c_input = input.view()
with nogil:
c_result = cpp_transform.nans_to_nulls(
c_input, _cs, mr.get_mr()
)

return (
gpumemoryview(
DeviceBuffer.c_from_unique_ptr(move(c_result.first), _stream, mr)
),
c_result.second
)


cpdef Column column_nans_to_nulls(
Column input,
Expand Down
26 changes: 1 addition & 25 deletions python/pylibcudf/tests/test_transform.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import math
Expand All @@ -11,30 +11,6 @@
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.Column.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)


def test_column_nans_to_nulls(has_nans):
if has_nans:
values = [1, float("nan"), float("nan"), None, 3, None]
Expand Down
Loading