From 4811dd5d00dcc1779ffb87b539595037ee2a93eb Mon Sep 17 00:00:00 2001 From: Muhammad Haseeb Date: Tue, 18 Aug 2026 01:31:06 +0000 Subject: [PATCH 1/4] Deprecate `apply_boolean_mask` in favor of `apply_retention_mask` --- cpp/benchmarks/filter/minmax_filter.cpp | 2 +- cpp/benchmarks/ndsh/utilities.cpp | 4 +- .../stream_compaction/apply_boolean_mask.cpp | 2 +- cpp/include/cudf/detail/stream_compaction.hpp | 2 +- .../cudf/lists/detail/stream_compaction.hpp | 2 +- cpp/include/cudf/lists/stream_compaction.hpp | 37 +++++++---- cpp/include/cudf/stream_compaction.hpp | 31 +++++++--- .../benchmarks/streaming/ndsh/q04.cpp | 2 +- .../benchmarks/streaming/ndsh/q09.cpp | 2 +- .../benchmarks/streaming/ndsh/q21.cpp | 6 +- cpp/libcudf_streaming/src/bloom_filter.cpp | 2 +- .../parquet/experimental/hybrid_scan_impl.hpp | 2 +- .../experimental/hybrid_scan_preprocess.cu | 2 +- cpp/src/join/sort_merge_join.cu | 5 +- .../stream_compaction/apply_boolean_mask.cu | 12 +++- .../stream_compaction/apply_boolean_mask.cu | 12 +++- cpp/tests/filter/filter_test.cpp | 10 +-- .../experimental/hybrid_scan_filters_test.cpp | 2 +- .../io/experimental/hybrid_scan_test.cpp | 6 +- .../io/parquet_deletion_vectors_test.cpp | 2 +- cpp/tests/io/parquet_reader_dict_test.cpp | 2 +- cpp/tests/io/parquet_reader_test.cpp | 54 ++++++++-------- .../apply_boolean_mask_tests.cpp | 28 ++++----- .../apply_boolean_mask_tests.cpp | 62 +++++++++---------- cpp/tests/streams/lists_test.cpp | 2 +- cpp/tests/streams/stream_compaction_test.cpp | 2 +- java/src/main/native/src/TableJni.cpp | 2 +- python/cudf/cudf/core/column/categorical.py | 8 +-- python/cudf/cudf/core/column/column.py | 24 ++++--- python/cudf/cudf/core/column/datetime.py | 8 +-- python/cudf/cudf/core/column/numerical.py | 2 +- python/cudf/cudf/core/column/string.py | 4 +- python/cudf/cudf/core/indexed_frame.py | 4 +- python/cudf/cudf/core/single_column_frame.py | 2 +- python/cudf/cudf/core/tools/datetimes.py | 2 +- python/cudf/cudf/testing/testing.py | 4 +- .../cudf_polars/containers/dataframe.py | 2 +- .../cudf_polars/dsl/expressions/selection.py | 2 +- .../cudf_polars/dsl/expressions/string.py | 2 +- .../cudf_polars/dsl/expressions/unary.py | 10 +-- .../libcudf/lists/stream_compaction.pxd | 7 +++ .../pylibcudf/libcudf/stream_compaction.pxd | 7 +++ python/pylibcudf/pylibcudf/lists.pxd | 7 +++ python/pylibcudf/pylibcudf/lists.pyi | 6 ++ python/pylibcudf/pylibcudf/lists.pyx | 38 +++++++++--- .../pylibcudf/pylibcudf/stream_compaction.pxd | 7 +++ .../pylibcudf/pylibcudf/stream_compaction.pyi | 6 ++ .../pylibcudf/pylibcudf/stream_compaction.pyx | 36 ++++++++--- .../pylibcudf/tests/test_stream_compaction.py | 12 ++-- 49 files changed, 312 insertions(+), 185 deletions(-) diff --git a/cpp/benchmarks/filter/minmax_filter.cpp b/cpp/benchmarks/filter/minmax_filter.cpp index 8925928e0143..ebe4f8b16b8c 100644 --- a/cpp/benchmarks/filter/minmax_filter.cpp +++ b/cpp/benchmarks/filter/minmax_filter.cpp @@ -131,7 +131,7 @@ void BM_filter_min_max(nvbench::state& state) auto filter_table = cudf::table_view{filter_column_views}; auto const filter_boolean = cudf::compute_column(predicate_table, tree.back(), stream, mr); auto const result = - cudf::apply_boolean_mask(filter_table, filter_boolean->view(), stream, mr); + cudf::apply_retention_mask(filter_table, filter_boolean->view(), stream, mr); } break; case engine_type::JIT: { cudf::filter_input predicate_inputs[] = { diff --git a/cpp/benchmarks/ndsh/utilities.cpp b/cpp/benchmarks/ndsh/utilities.cpp index 324ce8e9a88f..915d93fa505f 100644 --- a/cpp/benchmarks/ndsh/utilities.cpp +++ b/cpp/benchmarks/ndsh/utilities.cpp @@ -218,7 +218,7 @@ std::unique_ptr apply_filter(std::unique_ptr { CUDF_BENCHMARK_RANGE(); auto const boolean_mask = cudf::compute_column(table->table(), predicate); - auto result_table = cudf::apply_boolean_mask(table->table(), boolean_mask->view()); + auto result_table = cudf::apply_retention_mask(table->table(), boolean_mask->view()); return std::make_unique(std::move(result_table), table->column_names()); } @@ -226,7 +226,7 @@ std::unique_ptr apply_mask(std::unique_ptr c std::unique_ptr const& mask) { CUDF_BENCHMARK_RANGE(); - auto result_table = cudf::apply_boolean_mask(table->table(), mask->view()); + auto result_table = cudf::apply_retention_mask(table->table(), mask->view()); return std::make_unique(std::move(result_table), table->column_names()); } diff --git a/cpp/benchmarks/stream_compaction/apply_boolean_mask.cpp b/cpp/benchmarks/stream_compaction/apply_boolean_mask.cpp index 50bfca071a04..07d269d30778 100644 --- a/cpp/benchmarks/stream_compaction/apply_boolean_mask.cpp +++ b/cpp/benchmarks/stream_compaction/apply_boolean_mask.cpp @@ -70,7 +70,7 @@ void apply_mask_benchmark(nvbench::state& state, nvbench::type_list) state.exec(nvbench::exec_tag::sync, [&source_table, &mask, is_retention](nvbench::launch& launch) { if (is_retention) { - cudf::apply_boolean_mask(*source_table, mask->view()); + cudf::apply_retention_mask(*source_table, mask->view()); } else { cudf::apply_deletion_mask(*source_table, mask->view()); } diff --git a/cpp/include/cudf/detail/stream_compaction.hpp b/cpp/include/cudf/detail/stream_compaction.hpp index e506d34a5cc1..4307f030ce76 100644 --- a/cpp/include/cudf/detail/stream_compaction.hpp +++ b/cpp/include/cudf/detail/stream_compaction.hpp @@ -45,7 +45,7 @@ enum class mask_type : bool { }; /** - * @copydoc cudf::apply_boolean_mask + * @copydoc cudf::apply_retention_mask * * @param mask_kind Specifies how the boolean mask is treated (retentions or deletions) */ diff --git a/cpp/include/cudf/lists/detail/stream_compaction.hpp b/cpp/include/cudf/lists/detail/stream_compaction.hpp index fdcab3ec8367..48b759ce197c 100644 --- a/cpp/include/cudf/lists/detail/stream_compaction.hpp +++ b/cpp/include/cudf/lists/detail/stream_compaction.hpp @@ -14,7 +14,7 @@ namespace cudf { namespace lists::detail { /** - * @copydoc cudf::lists::apply_boolean_mask + * @copydoc cudf::lists::apply_retention_mask * * @param mask_kind Specifies how the boolean mask is treated (retentions or deletions) */ diff --git a/cpp/include/cudf/lists/stream_compaction.hpp b/cpp/include/cudf/lists/stream_compaction.hpp index 56fb806c307e..e5d10a84d487 100644 --- a/cpp/include/cudf/lists/stream_compaction.hpp +++ b/cpp/include/cudf/lists/stream_compaction.hpp @@ -24,35 +24,48 @@ namespace lists { */ /** - * @brief Filters elements in each row of `input` LIST column using `boolean_mask` + * @brief Filters elements in each row of `input` LIST column using `retention_mask` * LIST of booleans as a mask. * * Given an input `LIST` column and a list-of-bools column, the function produces * a new `LIST` column of the same type as `input`, where each element is copied - * from the input row *only* if the corresponding `boolean_mask` is non-null and `true`. + * from the input row *only* if the corresponding `retention_mask` is non-null and `true`. * * E.g. * @code{.pseudo} - * input = { {0,1,2}, {3,4}, {5,6,7}, {8,9} }; - * boolean_mask = { {0,1,1}, {1,0}, {1,1,1}, {0,0} }; - * results = { {1,2}, {3}, {5,6,7}, {} }; + * input = { {0,1,2}, {3,4}, {5,6,7}, {8,9} }; + * retention_mask = { {0,1,1}, {1,0}, {1,1,1}, {0,0} }; + * results = { {1,2}, {3}, {5,6,7}, {} }; * @endcode * - * `input` and `boolean_mask` must have the same number of rows. - * The output column has the same number of rows as the input column. - * An element is copied to an output row *only* if the corresponding boolean_mask element is `true`. + * An element is copied to an output row *only* if the corresponding @p retention_mask element is + * `true`. * An output row is invalid only if the input row is invalid. * - * @throws cudf::logic_error if `boolean_mask` is not a "lists of bools" column - * @throws cudf::logic_error if `input` and `boolean_mask` have different number of rows + * @throws cudf::logic_error if @p retention_mask is not a "lists of bools" column + * @throws cudf::logic_error if @p input` and @p retention_mask have different number of rows * * @param input The input list column view to be filtered - * @param boolean_mask A nullable list of bools column used to filter `input` elements + * @param retention_mask A nullable list of bools column used to filter `input` elements * @param stream CUDA stream used for device memory operations and kernel launches * @param mr Device memory resource used to allocate the returned table's device memory * @return List column of the same type as `input`, containing filtered list rows */ -std::unique_ptr apply_boolean_mask( +std::unique_ptr apply_retention_mask( + lists_column_view const& input, + lists_column_view const& retention_mask, + cuda::stream_ref stream = cudf::get_default_stream(), + rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref()); + +/** + * @brief Filters elements in each row of `input` LIST column using `boolean_mask` + * LIST of booleans as a mask. + * + * @deprecated in release 26.10. Use `apply_retention_mask` instead. + * + * @copydoc apply_retention_mask + */ +[[deprecated("Use apply_retention_mask() instead")]] std::unique_ptr apply_boolean_mask( lists_column_view const& input, lists_column_view const& boolean_mask, cuda::stream_ref stream = cudf::get_default_stream(), diff --git a/cpp/include/cudf/stream_compaction.hpp b/cpp/include/cudf/stream_compaction.hpp index 46e923fd8f53..23cae65a33da 100644 --- a/cpp/include/cudf/stream_compaction.hpp +++ b/cpp/include/cudf/stream_compaction.hpp @@ -190,7 +190,7 @@ std::unique_ptr drop_nans( rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref()); /** - * @brief Filters `input` using `boolean_mask` of boolean values as a mask. + * @brief Filters `input` using `retention_mask` of boolean values as a mask. * * Given an input `table_view` and a mask `column_view`, an element `i` from * each column_view of the `input` is copied to the corresponding output column @@ -200,18 +200,31 @@ std::unique_ptr
drop_nans( * @note if @p input.num_rows() is zero, there is no error, and an empty table * is returned. * - * @throws cudf::logic_error if `input.num_rows() != boolean_mask.size()`. - * @throws cudf::logic_error if `boolean_mask` is not `type_id::BOOL8` type. + * @throws cudf::logic_error if `input.num_rows() != retention_mask.size()`. + * @throws cudf::logic_error if @p retention_mask is not `type_id::BOOL8` type. * * @param[in] input The input table_view to filter - * @param[in] boolean_mask A nullable column_view of type type_id::BOOL8 used + * @param[in] retention_mask A nullable column_view of type type_id::BOOL8 used * as a mask to filter the `input`. * @param[in] stream CUDA stream used for device memory operations and kernel launches * @param[in] mr Device memory resource used to allocate the returned table's device memory - * @return Table containing copy of all rows of @p input passing - * the filter defined by @p boolean_mask. + * @return Table containing copy of all rows of @p input passing the filter defined by + * @p retention_mask. + */ +std::unique_ptr
apply_retention_mask( + table_view const& input, + column_view const& retention_mask, + rmm::cuda_stream_view stream = cudf::get_default_stream(), + rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref()); + +/** + * @brief Filters `input` using `boolean_mask` of boolean values as a mask. + * + * @deprecated in release 26.10. Use `apply_retention_mask` instead. + * + * @copydoc apply_retention_mask */ -std::unique_ptr
apply_boolean_mask( +[[deprecated("Use apply_retention_mask() instead")]] std::unique_ptr
apply_boolean_mask( table_view const& input, column_view const& boolean_mask, rmm::cuda_stream_view stream = cudf::get_default_stream(), @@ -236,8 +249,8 @@ std::unique_ptr
apply_boolean_mask( * as a mask to filter the `input`. * @param[in] stream CUDA stream used for device memory operations and kernel launches * @param[in] mr Device memory resource used to allocate the returned table's device memory - * @return Table containing copy of all rows of @p input that are not marked - * for deletion by @p deletion_mask. + * @return Table containing copy of all rows of @p input that are not marked for deletion + * by @p deletion_mask. */ std::unique_ptr
apply_deletion_mask( table_view const& input, diff --git a/cpp/libcudf_streaming/benchmarks/streaming/ndsh/q04.cpp b/cpp/libcudf_streaming/benchmarks/streaming/ndsh/q04.cpp index 86bc8482507e..682156b8e0d2 100644 --- a/cpp/libcudf_streaming/benchmarks/streaming/ndsh/q04.cpp +++ b/cpp/libcudf_streaming/benchmarks/streaming/ndsh/q04.cpp @@ -148,7 +148,7 @@ rapidsmpf::streaming::Actor filter_lineitem(std::shared_ptrview(), chunk_stream, mr); + cudf::apply_retention_mask(table.select({2}), mask->view(), chunk_stream, mr); co_await ch_out->send(cudf_streaming::to_message( msg.sequence_number(), std::make_unique(std::move(filtered_table), chunk_stream))); diff --git a/cpp/libcudf_streaming/benchmarks/streaming/ndsh/q09.cpp b/cpp/libcudf_streaming/benchmarks/streaming/ndsh/q09.cpp index 7bb35a4115c2..de441285c532 100644 --- a/cpp/libcudf_streaming/benchmarks/streaming/ndsh/q09.cpp +++ b/cpp/libcudf_streaming/benchmarks/streaming/ndsh/q09.cpp @@ -168,7 +168,7 @@ rapidsmpf::streaming::Actor filter_part(std::shared_ptrsend(cudf_streaming::to_message( msg.sequence_number(), std::make_unique( - cudf::apply_boolean_mask(table.select({0}), mask->view(), chunk_stream, mr), + cudf::apply_retention_mask(table.select({0}), mask->view(), chunk_stream, mr), chunk_stream))); } co_await ch_out->drain(ctx->executor()); diff --git a/cpp/libcudf_streaming/benchmarks/streaming/ndsh/q21.cpp b/cpp/libcudf_streaming/benchmarks/streaming/ndsh/q21.cpp index 7eaa08229187..48a73f015e56 100644 --- a/cpp/libcudf_streaming/benchmarks/streaming/ndsh/q21.cpp +++ b/cpp/libcudf_streaming/benchmarks/streaming/ndsh/q21.cpp @@ -211,7 +211,7 @@ rapidsmpf::streaming::Actor filter_lineitem(std::shared_ptrsend(cudf_streaming::to_message( msg.sequence_number(), std::make_unique( - cudf::apply_boolean_mask( + cudf::apply_retention_mask( chunk.table_view().select({0, 1}), mask->view(), chunk.stream(), ctx->br()->device_mr()), chunk.stream()))); } @@ -243,7 +243,7 @@ rapidsmpf::streaming::Actor filter_grouped_greater( co_await ch_out->send(cudf_streaming::to_message( msg.sequence_number(), std::make_unique( - cudf::apply_boolean_mask( + cudf::apply_retention_mask( chunk.table_view().select({0}), mask->view(), chunk.stream(), ctx->br()->device_mr()), chunk.stream()))); if (!released_lineitem_read) { @@ -278,7 +278,7 @@ rapidsmpf::streaming::Actor filter_grouped_equal( co_await ch_out->send(cudf_streaming::to_message( msg.sequence_number(), std::make_unique( - cudf::apply_boolean_mask( + cudf::apply_retention_mask( chunk.table_view().select({0}), mask->view(), chunk.stream(), ctx->br()->device_mr()), chunk.stream()))); } diff --git a/cpp/libcudf_streaming/src/bloom_filter.cpp b/cpp/libcudf_streaming/src/bloom_filter.cpp index c3411c25a6cb..aa35a7bbe392 100644 --- a/cpp/libcudf_streaming/src/bloom_filter.cpp +++ b/cpp/libcudf_streaming/src/bloom_filter.cpp @@ -150,7 +150,7 @@ rapidsmpf::streaming::Actor bloom_filter::apply( mask.data(), {}, 0}; - auto result = cudf::apply_boolean_mask( + auto result = cudf::apply_retention_mask( chunk.table_view(), mask_view, chunk_stream, ctx_->br()->device_mr()); std::ignore = std::move(chunk); std::ignore = std::move(res); diff --git a/cpp/src/io/parquet/experimental/hybrid_scan_impl.hpp b/cpp/src/io/parquet/experimental/hybrid_scan_impl.hpp index 4c2bf670953d..b7d36b010737 100644 --- a/cpp/src/io/parquet/experimental/hybrid_scan_impl.hpp +++ b/cpp/src/io/parquet/experimental/hybrid_scan_impl.hpp @@ -534,7 +534,7 @@ class hybrid_scan_reader_impl : public parquet::detail::reader_impl { * and only if in_row_mask[i] is valid and true * * Updates the output row mask to reflect the final valid and surviving rows from the input row - * mask. This is inline with the masking behavior of cudf::detail::apply_boolean_mask + * mask. This is inline with the masking behavior of cudf::detail::apply_mask * * @param in_row_mask Input row mask column * @param out_row_mask Output row mask column diff --git a/cpp/src/io/parquet/experimental/hybrid_scan_preprocess.cu b/cpp/src/io/parquet/experimental/hybrid_scan_preprocess.cu index 994176176a71..9392c80f08db 100644 --- a/cpp/src/io/parquet/experimental/hybrid_scan_preprocess.cu +++ b/cpp/src/io/parquet/experimental/hybrid_scan_preprocess.cu @@ -330,7 +330,7 @@ namespace { /** * @brief Computes the updated row mask value such that out_row_mask[i] = true, iff in_row_mask[i] - * is valid and true. This is inline with the masking behavior of cudf::apply_boolean_mask. + * is valid and true. This is inline with the masking behavior of cudf::apply_retention_mask. */ struct row_mask_update_fn { bool is_nullable; diff --git a/cpp/src/join/sort_merge_join.cu b/cpp/src/join/sort_merge_join.cu index 1c0ed633dfe8..f4488c6f0c52 100644 --- a/cpp/src/join/sort_merge_join.cu +++ b/cpp/src/join/sort_merge_join.cu @@ -14,12 +14,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -648,7 +648,8 @@ void sort_merge_join::preprocessed_table::apply_nonnull_filter(cuda::stream_ref "Something went wrong while dropping nulls in the unprocessed tables"); bool_mask->set_null_mask(_validity_mask.value(), _num_nulls.value(), stream); - _null_processed_table = apply_boolean_mask(_table_view, *bool_mask, stream, temp_mr); + _null_processed_table = + detail::apply_mask(_table_view, *bool_mask, detail::mask_type::RETENTION, stream, temp_mr); _null_processed_table_view = _null_processed_table.value()->view(); } diff --git a/cpp/src/lists/stream_compaction/apply_boolean_mask.cu b/cpp/src/lists/stream_compaction/apply_boolean_mask.cu index 50abf4fbd0cf..eefe135f233a 100644 --- a/cpp/src/lists/stream_compaction/apply_boolean_mask.cu +++ b/cpp/src/lists/stream_compaction/apply_boolean_mask.cu @@ -103,13 +103,21 @@ std::unique_ptr apply_mask(lists_column_view const& input, } } // namespace detail +std::unique_ptr apply_retention_mask(lists_column_view const& input, + lists_column_view const& retention_mask, + cuda::stream_ref stream, + rmm::device_async_resource_ref mr) +{ + CUDF_FUNC_RANGE(); + return detail::apply_mask(input, retention_mask, cudf::detail::mask_type::RETENTION, stream, mr); +} + std::unique_ptr apply_boolean_mask(lists_column_view const& input, lists_column_view const& boolean_mask, cuda::stream_ref stream, rmm::device_async_resource_ref mr) { - CUDF_FUNC_RANGE(); - return detail::apply_mask(input, boolean_mask, cudf::detail::mask_type::RETENTION, stream, mr); + return apply_retention_mask(input, boolean_mask, stream, mr); } std::unique_ptr apply_deletion_mask(lists_column_view const& input, diff --git a/cpp/src/stream_compaction/apply_boolean_mask.cu b/cpp/src/stream_compaction/apply_boolean_mask.cu index 41e6d9f79fad..623a4efaa041 100644 --- a/cpp/src/stream_compaction/apply_boolean_mask.cu +++ b/cpp/src/stream_compaction/apply_boolean_mask.cu @@ -96,13 +96,21 @@ std::unique_ptr
apply_mask(table_view const& input, /* * Filters a table_view using a column_view of boolean values as a mask. */ +std::unique_ptr
apply_retention_mask(table_view const& input, + column_view const& retention_mask, + rmm::cuda_stream_view stream, + rmm::device_async_resource_ref mr) +{ + CUDF_FUNC_RANGE(); + return detail::apply_mask(input, retention_mask, detail::mask_type::RETENTION, stream, mr); +} + std::unique_ptr
apply_boolean_mask(table_view const& input, column_view const& boolean_mask, rmm::cuda_stream_view stream, rmm::device_async_resource_ref mr) { - CUDF_FUNC_RANGE(); - return detail::apply_mask(input, boolean_mask, detail::mask_type::RETENTION, stream, mr); + return apply_retention_mask(input, boolean_mask, stream, mr); } std::unique_ptr
apply_deletion_mask(table_view const& input, diff --git a/cpp/tests/filter/filter_test.cpp b/cpp/tests/filter/filter_test.cpp index 01ad59d9e258..6bb0c53ca2c3 100644 --- a/cpp/tests/filter/filter_test.cpp +++ b/cpp/tests/filter/filter_test.cpp @@ -300,7 +300,7 @@ struct ast_expression_executor { cudf::table_view const& table) { auto booleans = cudf::compute_column(table, expr); - return cudf::apply_boolean_mask(table, booleans->view()); + return cudf::apply_retention_mask(table, booleans->view()); } }; @@ -349,7 +349,7 @@ TYPED_TEST(FilterExpressionTest, IsNull) auto result = Executor::filter(filter_expr, this->table); auto expected_filter = cudf::test::fixed_width_column_wrapper{{true, true, true, true, true, true, true, false}}; - auto expected_table = cudf::apply_boolean_mask(this->table, expected_filter); + auto expected_table = cudf::apply_retention_mask(this->table, expected_filter); CUDF_TEST_EXPECT_TABLES_EQUAL(expected_table->view(), result->view()); } @@ -365,7 +365,7 @@ TYPED_TEST(FilterExpressionTest, NullEqual) auto result = Executor::filter(null_equal_expr, this->table); auto expected_filter = cudf::test::fixed_width_column_wrapper{{true, false, true, true, true, true, true, true}}; - auto expected_table = cudf::apply_boolean_mask(this->table, expected_filter); + auto expected_table = cudf::apply_retention_mask(this->table, expected_filter); CUDF_TEST_EXPECT_TABLES_EQUAL(expected_table->view(), result->view()); } @@ -381,7 +381,7 @@ TYPED_TEST(FilterExpressionTest, NullLogicalAnd) auto result = Executor::filter(and_expr, this->table); auto expected_filter = cudf::test::fixed_width_column_wrapper{ {false, false, false, true, false, false, false, false}}; - auto expected_table = cudf::apply_boolean_mask(this->table, expected_filter); + auto expected_table = cudf::apply_retention_mask(this->table, expected_filter); CUDF_TEST_EXPECT_TABLES_EQUAL(expected_table->view(), result->view()); } @@ -397,7 +397,7 @@ TYPED_TEST(FilterExpressionTest, NullLogicalOr) auto result = Executor::filter(or_expr, this->table); auto expected_filter = cudf::test::fixed_width_column_wrapper{ {false, true, true, true, false, true, false, false}}; - auto expected_table = cudf::apply_boolean_mask(this->table, expected_filter); + auto expected_table = cudf::apply_retention_mask(this->table, expected_filter); CUDF_TEST_EXPECT_TABLES_EQUAL(expected_table->view(), result->view()); } diff --git a/cpp/tests/io/experimental/hybrid_scan_filters_test.cpp b/cpp/tests/io/experimental/hybrid_scan_filters_test.cpp index eee71f349ec7..e9cb54871e08 100644 --- a/cpp/tests/io/experimental/hybrid_scan_filters_test.cpp +++ b/cpp/tests/io/experimental/hybrid_scan_filters_test.cpp @@ -903,7 +903,7 @@ TEST_F(HybridScanFiltersTest, OffsetIndexOnlyDataPageMask) options, stream, mr); - auto const expected = cudf::apply_boolean_mask(written_table->view(), row_mask_view, stream, mr); + auto const expected = cudf::apply_retention_mask(written_table->view(), row_mask_view, stream, mr); CUDF_TEST_EXPECT_TABLES_EQUIVALENT(expected->view(), result.tbl->view()); // Without offset index, data-page pruning falls back to decoding all pages. diff --git a/cpp/tests/io/experimental/hybrid_scan_test.cpp b/cpp/tests/io/experimental/hybrid_scan_test.cpp index 6607c941e51c..ad1ec55e50e5 100644 --- a/cpp/tests/io/experimental/hybrid_scan_test.cpp +++ b/cpp/tests/io/experimental/hybrid_scan_test.cpp @@ -353,7 +353,7 @@ TEST_F(HybridScanTest, FilterDataPagesOnlyAndScanAllColumns) auto predicate = cudf::compute_column(written_table->view(), filter_expression); EXPECT_EQ(predicate->view().type().id(), cudf::type_id::BOOL8) << "Predicate filter should return a boolean"; - auto expected = cudf::apply_boolean_mask(written_table->view(), *predicate); + auto expected = cudf::apply_retention_mask(written_table->view(), *predicate); CUDF_TEST_EXPECT_TABLES_EQUIVALENT(expected->view(), read_table->view()); } @@ -838,7 +838,7 @@ TEST_F(HybridScanTest, ExtendedFilterExpressions) datasource_ref, filter, std::nullopt, case_sensitive_names, stream, mr); auto predicate = cudf::compute_column(written_table->view(), filter); - auto expected = cudf::apply_boolean_mask(written_table->view(), *predicate); + auto expected = cudf::apply_retention_mask(written_table->view(), *predicate); CUDF_TEST_EXPECT_TABLES_EQUIVALENT(expected->view(), read_single_step->view()); CUDF_TEST_EXPECT_TABLES_EQUIVALENT(expected->select({1, 0}), filter_table->view()); @@ -872,7 +872,7 @@ TEST_F(HybridScanTest, ExtendedFilterExpressions) datasource_ref, filter, std::nullopt, case_sensitive_names, stream, mr); auto predicate = cudf::compute_column(written_table->view(), filter); - auto expected = cudf::apply_boolean_mask(written_table->view(), *predicate); + auto expected = cudf::apply_retention_mask(written_table->view(), *predicate); CUDF_TEST_EXPECT_TABLES_EQUIVALENT(expected->view(), read_single_step->view()); CUDF_TEST_EXPECT_TABLES_EQUIVALENT(expected->select({1, 0}), filter_table->view()); diff --git a/cpp/tests/io/parquet_deletion_vectors_test.cpp b/cpp/tests/io/parquet_deletion_vectors_test.cpp index 735d0a1ec0a3..bb38c4077c20 100644 --- a/cpp/tests/io/parquet_deletion_vectors_test.cpp +++ b/cpp/tests/io/parquet_deletion_vectors_test.cpp @@ -216,7 +216,7 @@ std::unique_ptr build_expected_table( cuda::counting_iterator(input_table_view.num_columns()), std::back_inserter(index_and_columns), [&](auto col_idx) { return input_table_view.column(col_idx); }); - return cudf::apply_boolean_mask(cudf::table_view{index_and_columns}, row_mask_column, stream, mr); + return cudf::apply_retention_mask(cudf::table_view{index_and_columns}, row_mask_column, stream, mr); } /** diff --git a/cpp/tests/io/parquet_reader_dict_test.cpp b/cpp/tests/io/parquet_reader_dict_test.cpp index 80e2cf6dcf56..0ce0432df513 100644 --- a/cpp/tests/io/parquet_reader_dict_test.cpp +++ b/cpp/tests/io/parquet_reader_dict_test.cpp @@ -331,7 +331,7 @@ TEST_F(ParquetReaderDictTest, FilterWithOutputDictColumns) // Expected result: apply the same predicate to the input table on host-visible data. auto const predicate = cudf::compute_column(input_tbl, filter_expr); - auto const expected = cudf::apply_boolean_mask(input_tbl, predicate->view()); + auto const expected = cudf::apply_retention_mask(input_tbl, predicate->view()); ASSERT_LT(expected->num_rows(), num_rows) << "filter must remove some rows to be meaningful"; auto const read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}) diff --git a/cpp/tests/io/parquet_reader_test.cpp b/cpp/tests/io/parquet_reader_test.cpp index 08e48dd213eb..7aa71f4f6edc 100644 --- a/cpp/tests/io/parquet_reader_test.cpp +++ b/cpp/tests/io/parquet_reader_test.cpp @@ -1927,7 +1927,7 @@ TEST_F(ParquetReaderTest, FilterSimple) auto predicate = cudf::compute_column(*written_table, filter_expression); EXPECT_EQ(predicate->view().type().id(), cudf::type_id::BOOL8) << "Predicate filter should return a boolean"; - auto expected = cudf::apply_boolean_mask(*written_table, *predicate); + auto expected = cudf::apply_retention_mask(*written_table, *predicate); // To make sure AST filters out some elements EXPECT_LT(expected->num_rows(), written_table->num_rows()); @@ -2008,7 +2008,7 @@ TEST_F(ParquetReaderTest, FilterWithColumnProjection) auto col_ref = cudf::ast::column_name_reference{"cOL_uint32"}; auto read_expr = cudf::ast::operation(cudf::ast::ast_operator::LESS, col_ref, lit); auto projected_table = cudf::table_view{{src.get_column(2)}}; - auto expected = cudf::apply_boolean_mask(projected_table, *predicate); + auto expected = cudf::apply_retention_mask(projected_table, *predicate); auto read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}) .column_names({"col_Double"}) @@ -2040,7 +2040,7 @@ TEST_F(ParquetReaderTest, FilterWithColumnProjection) auto read_ref_expr = cudf::ast::operation(cudf::ast::ast_operator::LESS, col_index2, lit); auto projected_table = cudf::table_view{{src.get_column(2), src.get_column(0)}}; - auto expected = cudf::apply_boolean_mask(projected_table, *predicate); + auto expected = cudf::apply_retention_mask(projected_table, *predicate); auto read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}) .column_names({"col_Double", "col_UInt32"}) .case_sensitive_names(false) @@ -2099,7 +2099,7 @@ TEST_F(ParquetReaderTest, FilterReferenceExpression) // Expected result auto predicate = cudf::compute_column(src, filter_expression); - auto expected = cudf::apply_boolean_mask(src, *predicate); + auto expected = cudf::apply_retention_mask(src, *predicate); cudf::io::parquet_reader_options read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}) @@ -2136,7 +2136,7 @@ TEST_F(ParquetReaderTest, ExtendedFilterExpressions) auto filter = cudf::ast::operation(cudf::ast::ast_operator::LESS, col_ref_a, col_ref_b); auto predicate = cudf::compute_column(written_table, filter); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); cudf::io::parquet_reader_options read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}).filter(filter); @@ -2156,7 +2156,7 @@ TEST_F(ParquetReaderTest, ExtendedFilterExpressions) auto filter = cudf::ast::operation(cudf::ast::ast_operator::LOGICAL_AND, lhs, rhs); auto predicate = cudf::compute_column(written_table, filter); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); cudf::io::parquet_reader_options read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}).filter(filter); @@ -2175,7 +2175,7 @@ TEST_F(ParquetReaderTest, ExtendedFilterExpressions) auto filter = cudf::ast::operation(cudf::ast::ast_operator::LOGICAL_OR, lhs, rhs); auto predicate = cudf::compute_column(written_table, filter); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); cudf::io::parquet_reader_options read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}).filter(filter); @@ -2204,7 +2204,7 @@ TEST_F(ParquetReaderTest, ExtendedFilterExpressions) auto filter = cudf::ast::operation(cudf::ast::ast_operator::LOGICAL_OR, a_lt_10, and_expr); auto predicate = cudf::compute_column(written_table, filter); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); cudf::io::parquet_reader_options read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}).filter(filter); @@ -2224,7 +2224,7 @@ TEST_F(ParquetReaderTest, ExtendedFilterExpressions) auto filter = cudf::ast::operation(cudf::ast::ast_operator::LOGICAL_AND, literal_0, a_lt_50); auto predicate = cudf::compute_column(written_table, filter); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); cudf::io::parquet_reader_options read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}).filter(filter); @@ -2243,7 +2243,7 @@ TEST_F(ParquetReaderTest, ExtendedFilterExpressions) auto filter = cudf::ast::operation(cudf::ast::ast_operator::NOT, inner); auto predicate = cudf::compute_column(written_table, filter); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); cudf::io::parquet_reader_options read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}).filter(filter); @@ -2261,7 +2261,7 @@ TEST_F(ParquetReaderTest, ExtendedFilterExpressions) auto filter = cudf::ast::operation(cudf::ast::ast_operator::NULL_EQUAL, col_ref_a, literal_10); auto predicate = cudf::compute_column(written_table, filter); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); cudf::io::parquet_reader_options read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}).filter(filter); @@ -2284,7 +2284,7 @@ TEST_F(ParquetReaderTest, ExtendedFilterExpressions) auto filter = cudf::ast::operation(cudf::ast::ast_operator::LOGICAL_AND, lhs, rhs); auto predicate = cudf::compute_column(written_table, filter); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); cudf::io::parquet_reader_options read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}).filter(filter); @@ -2300,7 +2300,7 @@ TEST_F(ParquetReaderTest, ExtendedFilterExpressions) auto filter = cudf::ast::operation(cudf::ast::ast_operator::NOT, inner); auto predicate = cudf::compute_column(written_table, filter); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); cudf::io::parquet_reader_options read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}).filter(filter); @@ -2325,7 +2325,7 @@ TEST_F(ParquetReaderTest, FilterNamedExpression) // Expected result auto predicate = cudf::compute_column(src, table_filter); - auto expected = cudf::apply_boolean_mask(src, *predicate); + auto expected = cudf::apply_retention_mask(src, *predicate); cudf::io::parquet_reader_options read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}) @@ -2357,7 +2357,7 @@ TEST_F(ParquetReaderTest, FilterMultiple1) // Expected result auto predicate = cudf::compute_column(written_table, expr_3); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); auto si = cudf::io::source_info(filepath); auto builder = cudf::io::parquet_reader_options::builder(si).filter(expr_3); @@ -2403,7 +2403,7 @@ TEST_F(ParquetReaderTest, FilterMultiple2) // Expected result auto predicate = cudf::compute_column(written_table, expr_7); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); auto si = cudf::io::source_info(filepath); auto builder = cudf::io::parquet_reader_options::builder(si).filter(expr_7); @@ -2458,7 +2458,7 @@ TEST_F(ParquetReaderTest, FilterMultiple3) cudf::ast::operation(cudf::ast::ast_operator::LOGICAL_AND, expr_4_ref, expr_5_ref); auto expr_7_ref = cudf::ast::operation(cudf::ast::ast_operator::LOGICAL_OR, expr_3, expr_6_ref); auto predicate = cudf::compute_column(written_table, expr_7_ref); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); auto si = cudf::io::source_info(filepath); auto builder = cudf::io::parquet_reader_options::builder(si).filter(expr_7); @@ -2509,7 +2509,7 @@ TEST_F(ParquetReaderTest, FilterSupported) // Expected result auto predicate = cudf::compute_column(written_table, expr_9); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); auto si = cudf::io::source_info(filepath); auto builder = cudf::io::parquet_reader_options::builder(si).filter(expr_9); @@ -2551,7 +2551,7 @@ TEST_F(ParquetReaderTest, FilterSupported2) auto test_expr = [&](auto& expr) { // Expected result auto predicate = cudf::compute_column(written_table, expr); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); // tests auto builder = cudf::io::parquet_reader_options::builder(si).filter(expr); @@ -2653,7 +2653,7 @@ TEST_F(ParquetReaderTest, FilterErrors) // Expected result throw to show that the filter expression is invalid, // not a limitation of the parquet predicate pushdown. auto predicate = cudf::compute_column(written_table, expr_8); - EXPECT_THROW(cudf::apply_boolean_mask(written_table, *predicate), cudf::logic_error); + EXPECT_THROW(cudf::apply_retention_mask(written_table, *predicate), cudf::logic_error); } // Filtering AST - INT64(table[0] < 100) non-bool expression @@ -2702,7 +2702,7 @@ TEST_F(ParquetReaderTest, FilterNoStats) // Expected result auto predicate = cudf::compute_column(written_table, expr); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); // tests auto builder = cudf::io::parquet_reader_options::builder(si).filter(expr); @@ -2745,9 +2745,9 @@ TEST_F(ParquetReaderTest, FilterFloatNAN) // Expected result auto predicate0 = cudf::compute_column(written_table, expr_eq); - auto expected0 = cudf::apply_boolean_mask(written_table, *predicate0); + auto expected0 = cudf::apply_retention_mask(written_table, *predicate0); auto predicate1 = cudf::compute_column(written_table, expr_neq); - auto expected1 = cudf::apply_boolean_mask(written_table, *predicate1); + auto expected1 = cudf::apply_retention_mask(written_table, *predicate1); // tests auto builder0 = cudf::io::parquet_reader_options::builder(si).filter(expr_eq); @@ -3925,7 +3925,7 @@ void filter_typed_test() auto const predicate = cudf::compute_column(written_table, ref_filter); EXPECT_EQ(predicate->view().type().id(), cudf::type_id::BOOL8) << "Predicate filter should return a boolean"; - auto const expected = cudf::apply_boolean_mask(written_table, *predicate); + auto const expected = cudf::apply_retention_mask(written_table, *predicate); // Reading with Predicate Pushdown cudf::io::parquet_reader_options read_opts = @@ -4067,7 +4067,7 @@ void filter_unary_operation_typed_test() auto const predicate = cudf::compute_column(written_table, ref_filter); EXPECT_EQ(predicate->view().type().id(), cudf::type_id::BOOL8) << "Predicate filter should return a boolean"; - auto const expected = cudf::apply_boolean_mask(written_table, *predicate); + auto const expected = cudf::apply_retention_mask(written_table, *predicate); // JIT does not support nullness-dependent operators such as IS_NULL // Ref: https://github.com/rapidsai/cudf/issues/20177 @@ -4525,7 +4525,7 @@ void row_bounds_and_filter_test() cudf::test::iterators::no_nulls()}; cudf::table_view const expected_row_bounded({int64_col_row_bounded}); auto predicate = cudf::compute_column(expected_row_bounded, filter_expression); - auto expected = cudf::apply_boolean_mask(expected_row_bounded, *predicate); + auto expected = cudf::apply_retention_mask(expected_row_bounded, *predicate); auto const in_opts = cudf::io::parquet_reader_options::builder( cudf::io::source_info{std::vector{num_files, filepath}}) @@ -5347,7 +5347,7 @@ TEST_F(ParquetReaderTest, DuplicateColumnSelection) auto filter_expr = cudf::ast::operation(cudf::ast::ast_operator::LESS_EQUAL, col_ref, literal); auto const predicate = cudf::test::fixed_width_column_wrapper{true, true, true, false, false}.release(); - auto const expected = cudf::apply_boolean_mask(tbl.select({0, 1}), predicate->view()); + auto const expected = cudf::apply_retention_mask(tbl.select({0, 1}), predicate->view()); auto const read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}) diff --git a/cpp/tests/lists/stream_compaction/apply_boolean_mask_tests.cpp b/cpp/tests/lists/stream_compaction/apply_boolean_mask_tests.cpp index 4a782ad8e913..9229e45d9482 100644 --- a/cpp/tests/lists/stream_compaction/apply_boolean_mask_tests.cpp +++ b/cpp/tests/lists/stream_compaction/apply_boolean_mask_tests.cpp @@ -15,7 +15,7 @@ namespace cudf::test { using namespace iterators; using cudf::lists_column_view; -using cudf::lists::apply_boolean_mask; +using cudf::lists::apply_retention_mask; template using lists = lists_column_wrapper; @@ -43,7 +43,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, StraightLine) { // Unsliced. - auto filtered = apply_boolean_mask(lists_column_view{*input}, lists_column_view{filter}); + auto filtered = apply_retention_mask(lists_column_view{*input}, lists_column_view{filter}); auto expected = lists{{0, 2}, {4}, {6, 8}, {0}, {2, 4}, {6}}; CUDF_TEST_EXPECT_COLUMNS_EQUAL(*filtered, expected); } @@ -52,7 +52,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, StraightLine) auto sliced = cudf::slice(*input, {1, input->size()}).front(); // == lists_t {{4, 5}, {6, 7, 8, 9}, {0, 1}, {2, 3, 4, 5}, {6, 7}}; auto filter = filter_t{{0, 1}, {0, 1, 0, 1}, {1, 1}, {0, 1, 0, 1}, {0, 0}}; - auto filtered = apply_boolean_mask(lists_column_view{sliced}, lists_column_view{filter}); + auto filtered = apply_retention_mask(lists_column_view{sliced}, lists_column_view{filter}); auto expected = lists{{5}, {7, 9}, {0, 1}, {3, 5}, {}}; CUDF_TEST_EXPECT_COLUMNS_EQUAL(*filtered, expected); } @@ -75,7 +75,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, NullElementsInTheListRows) { // Unsliced. - auto filtered = apply_boolean_mask(lists_column_view{*input}, lists_column_view{filter}); + auto filtered = apply_retention_mask(lists_column_view{*input}, lists_column_view{filter}); auto expected = lists{{0, 2}, lists{{X}, null_at(0)}, {6, 8}, @@ -89,7 +89,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, NullElementsInTheListRows) auto sliced = cudf::slice(*input, {1, input->size()}).front(); // == lists_t {{X, 5}, {6, 7, 8, 9}, {0, 1}, {X, 3, 4, X}, {X, X}}; auto filter = filter_t{{0, 1}, {0, 1, 0, 1}, {1, 1}, {0, 1, 0, 1}, {0, 0}}; - auto filtered = apply_boolean_mask(lists_column_view{sliced}, lists_column_view{filter}); + auto filtered = apply_retention_mask(lists_column_view{sliced}, lists_column_view{filter}); auto expected = lists{{5}, {7, 9}, {0, 1}, lists{{3, X}, null_at(1)}, {}}; CUDF_TEST_EXPECT_COLUMNS_EQUAL(*filtered, expected); } @@ -105,7 +105,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, NullListRowsInTheInputColumn) { // Unsliced. - auto filtered = apply_boolean_mask(lists_column_view{*input}, lists_column_view{filter}); + auto filtered = apply_retention_mask(lists_column_view{*input}, lists_column_view{filter}); auto expected = lists{{{0, 2}, {}, {6, 8}, {}, {2, 4}, {6}}, nulls_at({1, 3})}; CUDF_TEST_EXPECT_COLUMNS_EQUAL(*filtered, expected); } @@ -114,7 +114,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, NullListRowsInTheInputColumn) auto sliced = cudf::slice(*input, {1, input->size()}).front(); // == lists_t{{{}, {6, 7, 8, 9}, {}, {2, 3, 4, 5}, {6, 7}}, nulls_at({0,2})}; auto filter = filter_t{{}, {0, 1, 0, 1}, {}, {0, 1, 0, 1}, {0, 0}}; - auto filtered = apply_boolean_mask(lists_column_view{sliced}, lists_column_view{filter}); + auto filtered = apply_retention_mask(lists_column_view{sliced}, lists_column_view{filter}); auto expected = lists{{{}, {7, 9}, {}, {3, 5}, {}}, nulls_at({0, 2})}; CUDF_TEST_EXPECT_COLUMNS_EQUAL(*filtered, expected); } @@ -123,7 +123,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, NullListRowsInTheInputColumn) auto sliced = cudf::slice(*input, {2, input->size()}).front(); // == lists_t{{{6, 7, 8, 9}, {}, {2, 3, 4, 5}, {6, 7}}, null_at(1)}; auto filter = filter_t{{0, 1, 0, 1}, {}, {0, 1, 0, 1}, {0, 0}}; - auto filtered = apply_boolean_mask(lists_column_view{sliced}, lists_column_view{filter}); + auto filtered = apply_retention_mask(lists_column_view{sliced}, lists_column_view{filter}); auto expected = lists{{{7, 9}, {}, {3, 5}, {}}, null_at(1)}; CUDF_TEST_EXPECT_COLUMNS_EQUAL(*filtered, expected); } @@ -152,7 +152,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, StructInput) // The input should now look as follows: (String child dropped for brevity.) // Input: {[0, 1], [2], [3, 4, 5], [], [6, 7], [], [8, 9]} auto const filter = filter_t{{1, 1}, {0}, {0, 1, 0}, {}, {1, 0}, {}, {0, 1}}; - auto const result = apply_boolean_mask(lists_column_view{*input}, lists_column_view{filter}); + auto const result = apply_retention_mask(lists_column_view{*input}, lists_column_view{filter}); auto const expected = [] { auto child_num = fwcw{0, 1, 4, 6, 9}; auto child_str = strings{"0", "1", "4", "6", "9"}; @@ -174,7 +174,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, StructInput) // Input: {[2], [3, 4, 5], [], [6, 7], [], [8, 9]} auto const filter = filter_t{{0}, {0, 1, 0}, {}, {1, 0}, {}, {0, 1}}; auto const result = - apply_boolean_mask(lists_column_view{sliced_input}, lists_column_view{filter}); + apply_retention_mask(lists_column_view{sliced_input}, lists_column_view{filter}); auto const expected = [] { auto child_num = fwcw{4, 6, 9}; auto child_str = strings{"4", "6", "9"}; @@ -201,7 +201,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, NullsInBooleanMask) auto mask_child = fwcw{{1, X, 1, 0, X, X, 0, 1, 0}, nulls_at({1, 4, 5})}; auto mask = cudf::make_lists_column(3, offsets{0, 3, 5, 9}.release(), mask_child.release(), 0, {}); - auto filtered = apply_boolean_mask(lists_column_view{input}, lists_column_view{*mask}); + auto filtered = apply_retention_mask(lists_column_view{input}, lists_column_view{*mask}); auto expected = lists{{10, 30}, lists{}, {80}}; CUDF_TEST_EXPECT_COLUMNS_EQUAL(*filtered, expected); } @@ -210,7 +210,7 @@ TEST_F(ApplyBooleanMaskTest, Trivial) { auto const input = lists{}; auto const filter = filter_t{}; - auto const result = apply_boolean_mask(lists_column_view{input}, lists_column_view{filter}); + auto const result = apply_retention_mask(lists_column_view{input}, lists_column_view{filter}); CUDF_TEST_EXPECT_COLUMNS_EQUAL(*result, lists{}); } @@ -220,14 +220,14 @@ TEST_F(ApplyBooleanMaskTest, Failure) // Invalid mask type. auto const input = lists{{1, 2, 3}, {4, 5, 6}}; auto const filter = lists{{0, 0, 0}}; - EXPECT_THROW(apply_boolean_mask(lists_column_view{input}, lists_column_view{filter}), + EXPECT_THROW(apply_retention_mask(lists_column_view{input}, lists_column_view{filter}), cudf::logic_error); } { // Mismatched number of rows. auto const input = lists{{1, 2, 3}, {4, 5, 6}}; auto const filter = filter_t{{0, 0, 0}}; - EXPECT_THROW(apply_boolean_mask(lists_column_view{input}, lists_column_view{filter}), + EXPECT_THROW(apply_retention_mask(lists_column_view{input}, lists_column_view{filter}), cudf::logic_error); } } diff --git a/cpp/tests/stream_compaction/apply_boolean_mask_tests.cpp b/cpp/tests/stream_compaction/apply_boolean_mask_tests.cpp index 81f68b99cad9..b4b7a6c45c1b 100644 --- a/cpp/tests/stream_compaction/apply_boolean_mask_tests.cpp +++ b/cpp/tests/stream_compaction/apply_boolean_mask_tests.cpp @@ -22,18 +22,18 @@ #include #include -struct ApplyBooleanMask : public cudf::test::BaseFixture {}; +struct ApplyRetentionMask : public cudf::test::BaseFixture {}; -TEST_F(ApplyBooleanMask, ZeroColumnsPreservesRowCount) +TEST_F(ApplyRetentionMask, ZeroColumnsPreservesRowCount) { cudf::table_view input{std::vector{}, 4}; cudf::test::fixed_width_column_wrapper boolean_mask{{true, false, true, true}}; - auto got = cudf::apply_boolean_mask(input, boolean_mask); + auto got = cudf::apply_retention_mask(input, boolean_mask); EXPECT_EQ(got->num_columns(), 0); EXPECT_EQ(got->num_rows(), 3); } -TEST_F(ApplyBooleanMask, NonNullBooleanMask) +TEST_F(ApplyRetentionMask, NonNullBooleanMask) { cudf::test::fixed_width_column_wrapper col1{{true, false, true, false, true, false}, {1, 1, 0, 1, 1, 0}}; @@ -47,12 +47,12 @@ TEST_F(ApplyBooleanMask, NonNullBooleanMask) cudf::test::fixed_width_column_wrapper col3_expected{{10, 70, 2}, {1, 0, 1}}; cudf::table_view expected{{col1_expected, col2_expected, col3_expected}}; - auto got = cudf::apply_boolean_mask(input, boolean_mask); + auto got = cudf::apply_retention_mask(input, boolean_mask); CUDF_TEST_EXPECT_TABLES_EQUAL(expected, got->view()); } -TEST_F(ApplyBooleanMask, NullBooleanMask) +TEST_F(ApplyRetentionMask, NullBooleanMask) { cudf::test::fixed_width_column_wrapper col1{{true, false, true, false, true, false}, {1, 1, 0, 1, 1, 0}}; @@ -66,12 +66,12 @@ TEST_F(ApplyBooleanMask, NullBooleanMask) cudf::test::fixed_width_column_wrapper col3_expected{{70, 2}, {0, 1}}; cudf::table_view expected{{col1_expected, col2_expected, col3_expected}}; - auto got = cudf::apply_boolean_mask(input, boolean_mask); + auto got = cudf::apply_retention_mask(input, boolean_mask); CUDF_TEST_EXPECT_TABLES_EQUAL(expected, got->view()); } -TEST_F(ApplyBooleanMask, EmptyMask) +TEST_F(ApplyRetentionMask, EmptyMask) { cudf::test::fixed_width_column_wrapper col1{{true, false, true, false, true, false}, {1, 1, 0, 1, 1, 0}}; @@ -84,12 +84,12 @@ TEST_F(ApplyBooleanMask, EmptyMask) cudf::test::fixed_width_column_wrapper col3_expected{}; cudf::table_view expected{{col1_expected, col2_expected, col3_expected}}; - auto got = cudf::apply_boolean_mask(input, boolean_mask); + auto got = cudf::apply_retention_mask(input, boolean_mask); CUDF_TEST_EXPECT_TABLES_EQUAL(expected, got->view()); } -TEST_F(ApplyBooleanMask, WrongMaskType) +TEST_F(ApplyRetentionMask, WrongMaskType) { cudf::test::fixed_width_column_wrapper col1{{true, false, true, false, true, false}, {1, 1, 0, 1, 1, 0}}; @@ -99,10 +99,10 @@ TEST_F(ApplyBooleanMask, WrongMaskType) cudf::test::fixed_width_column_wrapper boolean_mask{ {true, false, true, false, true, false}}; - EXPECT_THROW(cudf::apply_boolean_mask(input, boolean_mask), cudf::logic_error); + EXPECT_THROW(cudf::apply_retention_mask(input, boolean_mask), cudf::logic_error); } -TEST_F(ApplyBooleanMask, MaskAndInputSizeMismatch) +TEST_F(ApplyRetentionMask, MaskAndInputSizeMismatch) { cudf::test::fixed_width_column_wrapper col1{{true, false, true, false, true, false}, {1, 1, 0, 1, 1, 0}}; @@ -111,10 +111,10 @@ TEST_F(ApplyBooleanMask, MaskAndInputSizeMismatch) cudf::table_view input{{col1, col2, col3}}; cudf::test::fixed_width_column_wrapper boolean_mask{{true, false, true, false, true}}; - EXPECT_THROW(cudf::apply_boolean_mask(input, boolean_mask), cudf::logic_error); + EXPECT_THROW(cudf::apply_retention_mask(input, boolean_mask), cudf::logic_error); } -TEST_F(ApplyBooleanMask, StringColumnTest) +TEST_F(ApplyRetentionMask, StringColumnTest) { cudf::test::strings_column_wrapper col1{ {"This", "is", "the", "a", "k12", "string", "table", "column"}, {1, 1, 1, 1, 1, 0, 1, 1}}; @@ -125,12 +125,12 @@ TEST_F(ApplyBooleanMask, StringColumnTest) {1, 1, 1, 0, 1}}; cudf::table_view expected{{col1_expected}}; - auto got = cudf::apply_boolean_mask(input, boolean_mask); + auto got = cudf::apply_retention_mask(input, boolean_mask); CUDF_TEST_EXPECT_TABLES_EQUAL(expected, got->view()); } -TEST_F(ApplyBooleanMask, withoutNullString) +TEST_F(ApplyRetentionMask, withoutNullString) { cudf::test::strings_column_wrapper col1({"d", "e", "a", "d", "k", "d", "l"}); cudf::table_view cudf_table_in_view{{col1}}; @@ -139,7 +139,7 @@ TEST_F(ApplyBooleanMask, withoutNullString) cudf::column_view bool_filter_col(bool_filter); std::unique_ptr filteredTable = - cudf::apply_boolean_mask(cudf_table_in_view, bool_filter_col); + cudf::apply_retention_mask(cudf_table_in_view, bool_filter_col); cudf::table_view tableView = filteredTable->view(); cudf::test::strings_column_wrapper expect_col1({"d", "e", "k"}); @@ -148,7 +148,7 @@ TEST_F(ApplyBooleanMask, withoutNullString) CUDF_TEST_EXPECT_TABLES_EQUAL(expect_cudf_table_view, tableView); } -TEST_F(ApplyBooleanMask, FixedPointColumnTest) +TEST_F(ApplyRetentionMask, FixedPointColumnTest) { using namespace numeric; using decimal32_wrapper = cudf::test::fixed_point_column_wrapper; @@ -162,7 +162,7 @@ TEST_F(ApplyBooleanMask, FixedPointColumnTest) cudf::column_view bool_filter_col(bool_filter); std::unique_ptr filteredTable = - cudf::apply_boolean_mask(cudf_table_in_view, bool_filter_col); + cudf::apply_retention_mask(cudf_table_in_view, bool_filter_col); cudf::table_view tableView = filteredTable->view(); auto const expect_col1 = decimal32_wrapper{{10, 40, 2}, scale_type{-1}}; @@ -172,7 +172,7 @@ TEST_F(ApplyBooleanMask, FixedPointColumnTest) CUDF_TEST_EXPECT_TABLES_EQUAL(expect_cudf_table_view, tableView); } -TEST_F(ApplyBooleanMask, FixedPointLargeColumnTest) +TEST_F(ApplyRetentionMask, FixedPointLargeColumnTest) { cudf::size_type const num_rows = 10000; @@ -198,7 +198,7 @@ TEST_F(ApplyBooleanMask, FixedPointLargeColumnTest) cudf::column_view bool_filter_col(bool_filter); std::unique_ptr filteredTable = - cudf::apply_boolean_mask(cudf_table_in_view, bool_filter_col); + cudf::apply_retention_mask(cudf_table_in_view, bool_filter_col); cudf::table_view tableView = filteredTable->view(); std::vector expect_dec32_data; @@ -225,7 +225,7 @@ TEST_F(ApplyBooleanMask, FixedPointLargeColumnTest) CUDF_TEST_EXPECT_TABLES_EQUAL(expect_cudf_table_view, tableView); } -TEST_F(ApplyBooleanMask, NoNullInput) +TEST_F(ApplyRetentionMask, NoNullInput) { cudf::test::fixed_width_column_wrapper col( {9668, 9590, 9526, 9205, 9434, 9347, 9160, 9569, 9143, 9807, 9606, 9446, 9279, 9822, 9691}); @@ -248,11 +248,11 @@ TEST_F(ApplyBooleanMask, NoNullInput) cudf::test::fixed_width_column_wrapper col_expected( {9526, 9347, 9569, 9807, 9279, 9691}); cudf::table_view expected({col_expected}); - auto got = cudf::apply_boolean_mask(input, mask); + auto got = cudf::apply_retention_mask(input, mask); CUDF_TEST_EXPECT_TABLES_EQUAL(expected, got->view()); } -TEST_F(ApplyBooleanMask, CorrectNullCount) +TEST_F(ApplyRetentionMask, CorrectNullCount) { cudf::size_type inputRows = 471234; @@ -267,14 +267,14 @@ TEST_F(ApplyBooleanMask, CorrectNullCount) cudf::detail::make_counting_transform_iterator(0, [](auto i) { return (i % 277) == 0; }); cudf::test::fixed_width_column_wrapper boolean_mask(seq3, seq3 + inputRows); - auto got = cudf::apply_boolean_mask(input, boolean_mask); + auto got = cudf::apply_retention_mask(input, boolean_mask); auto out_col = got->get_column(0).view(); auto expected_null_count = cudf::null_count(out_col.null_mask(), 0, out_col.size()); ASSERT_EQ(out_col.null_count(), expected_null_count); } -TEST_F(ApplyBooleanMask, StructFiltering) +TEST_F(ApplyRetentionMask, StructFiltering) { using namespace cudf::test; @@ -285,7 +285,7 @@ TEST_F(ApplyBooleanMask, StructFiltering) auto filter_mask = fixed_width_column_wrapper{{1, 1, 1, 1, 1, 0, 0, 0, 0, 0}}; - auto filtered_table = cudf::apply_boolean_mask(cudf::table_view({struct_column}), filter_mask); + auto filtered_table = cudf::apply_retention_mask(cudf::table_view({struct_column}), filter_mask); auto filtered_struct_column = filtered_table->get_column(0); // Compare against expected results. @@ -297,7 +297,7 @@ TEST_F(ApplyBooleanMask, StructFiltering) CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(filtered_struct_column, expected_struct_column); } -TEST_F(ApplyBooleanMask, ListOfStructsFiltering) +TEST_F(ApplyRetentionMask, ListOfStructsFiltering) { using namespace cudf::test; @@ -320,7 +320,7 @@ TEST_F(ApplyBooleanMask, ListOfStructsFiltering) auto filter_mask = fixed_width_column_wrapper{{1, 0, 1, 0, 1}}; auto filtered_table = - cudf::apply_boolean_mask(cudf::table_view({list_of_structs_column->view()}), filter_mask); + cudf::apply_retention_mask(cudf::table_view({list_of_structs_column->view()}), filter_mask); auto filtered_list_column = filtered_table->get_column(0); // Compare against expected values. @@ -343,7 +343,7 @@ TEST_F(ApplyBooleanMask, ListOfStructsFiltering) expected_list_of_structs_column->view()); } -TEST_F(ApplyBooleanMask, StructOfListsFiltering) +TEST_F(ApplyRetentionMask, StructOfListsFiltering) { using namespace cudf::test; @@ -353,7 +353,7 @@ TEST_F(ApplyBooleanMask, StructOfListsFiltering) auto structs_column = structs_column_wrapper{{lists_column}}; auto filter_mask = fixed_width_column_wrapper{{1, 0, 1, 0, 1}}; - auto filtered_table = cudf::apply_boolean_mask(cudf::table_view({structs_column}), filter_mask); + auto filtered_table = cudf::apply_retention_mask(cudf::table_view({structs_column}), filter_mask); auto filtered_lists_column = filtered_table->get_column(0); diff --git a/cpp/tests/streams/lists_test.cpp b/cpp/tests/streams/lists_test.cpp index fd11d05aa1e7..ec875515de0b 100644 --- a/cpp/tests/streams/lists_test.cpp +++ b/cpp/tests/streams/lists_test.cpp @@ -149,7 +149,7 @@ TEST_F(ListTest, ApplyBooleanMask) cudf::test::lists_column_wrapper list_col{{0, 1}, {2, 3, 7, 8}, {4, 5}}; cudf::test::lists_column_wrapper boolean_mask{ {false, true}, {true, true, true, false}, {false, true}}; - cudf::lists::apply_boolean_mask(list_col, boolean_mask, cudf::test::get_default_stream()); + cudf::lists::apply_retention_mask(list_col, boolean_mask, cudf::test::get_default_stream()); } TEST_F(ListTest, ApplyDeletionMask) diff --git a/cpp/tests/streams/stream_compaction_test.cpp b/cpp/tests/streams/stream_compaction_test.cpp index 9bf2e99916d9..af128f222719 100644 --- a/cpp/tests/streams/stream_compaction_test.cpp +++ b/cpp/tests/streams/stream_compaction_test.cpp @@ -365,7 +365,7 @@ TEST_F(StreamCompactionTest, ApplyBooleanMask) cudf::table_view input({col}); auto const col_expected = int32s_col{9526, 9347, 9569, 9807, 9279, 9691}; cudf::table_view expected({col_expected}); - auto const result = cudf::apply_boolean_mask(input, mask, cudf::test::get_default_stream()); + auto const result = cudf::apply_retention_mask(input, mask, cudf::test::get_default_stream()); CUDF_TEST_EXPECT_TABLES_EQUAL(expected, *result); } diff --git a/java/src/main/native/src/TableJni.cpp b/java/src/main/native/src/TableJni.cpp index 6fd64ebbb1ef..83eb7c88b847 100644 --- a/java/src/main/native/src/TableJni.cpp +++ b/java/src/main/native/src/TableJni.cpp @@ -4092,7 +4092,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_filter(JNIEnv* env, cudf::jni::auto_set_device(env); auto const input = reinterpret_cast(input_jtable); auto const mask = reinterpret_cast(mask_jcol); - return convert_table_for_return(env, cudf::apply_boolean_mask(*input, *mask)); + return convert_table_for_return(env, cudf::apply_retention_mask(*input, *mask)); } JNI_CATCH(env, 0); } diff --git a/python/cudf/cudf/core/column/categorical.py b/python/cudf/cudf/core/column/categorical.py index 4e4ef85803de..4d199fad800b 100644 --- a/python/cudf/cudf/core/column/categorical.py +++ b/python/cudf/cudf/core/column/categorical.py @@ -415,7 +415,7 @@ def find_and_replace( if old_plc.null_count() == 1: # Get the replacement value for the null in old_col old_isnull_plc = plc.unary.is_null(old_plc) - filtered_table = plc.stream_compaction.apply_boolean_mask( + filtered_table = plc.stream_compaction.apply_retention_mask( plc.Table([new_plc]), old_isnull_plc ) # We know there's exactly 1 null, so filtered result has 1 row @@ -455,14 +455,14 @@ def find_and_replace( if new_plc.null_count() > 0: # Any value mapped to null is dropped in the result new_isnull_plc = plc.unary.is_null(new_plc) - filtered_table = plc.stream_compaction.apply_boolean_mask( + filtered_table = plc.stream_compaction.apply_retention_mask( plc.Table([old_plc]), new_isnull_plc ) drop_values = ColumnBase.create( filtered_table.columns()[0], to_replace_col.dtype ) cur_categories = replaced.categories - new_categories = cur_categories.apply_boolean_mask( + new_categories = cur_categories.apply_retention_mask( cur_categories.isin(drop_values).unary_operator("not") ) replaced = replaced._set_categories(new_categories) @@ -1001,7 +1001,7 @@ def remove_categories( if not removals_mask.all(): raise ValueError("removals must all be in old categories") - new_categories = self.categories.apply_boolean_mask( + new_categories = self.categories.apply_retention_mask( self.categories.isin(removals).unary_operator("not") ) if not self._categories_equal(new_categories): diff --git a/python/cudf/cudf/core/column/column.py b/python/cudf/cudf/core/column/column.py index d6e57b96576c..9ee677575090 100644 --- a/python/cudf/cudf/core/column/column.py +++ b/python/cudf/cudf/core/column/column.py @@ -1260,7 +1260,7 @@ def _find_and_replace_with_dedup( replaced = self if old_plc.null_count() == 1: old_isnull_plc = plc.unary.is_null(old_plc) - (filtered_column,) = plc.stream_compaction.apply_boolean_mask( + (filtered_column,) = plc.stream_compaction.apply_retention_mask( plc.Table([new_plc]), old_isnull_plc ).columns() replacement_for_null = filtered_column.to_scalar().to_py() @@ -1833,7 +1833,7 @@ def _scatter_by_column( # Both value and key are aligned to self. Thus, the values # corresponding to the false values in key should be # ignored. - value = value.apply_boolean_mask(key) + value = value.apply_retention_mask(key) # After applying boolean mask, the length of value equals # the number of elements to scatter, we can skip computing # the sum of ``key`` below. @@ -2035,8 +2035,8 @@ def interpolate(self, index: Index) -> ColumnBase: # Each point is evenly spaced, index values don't matter known_x = cp.flatnonzero(valid_locs.values) else: - known_x = index._column.apply_boolean_mask(valid_locs).values - known_y = col.apply_boolean_mask(valid_locs).values + known_x = index._column.apply_retention_mask(valid_locs).values + known_y = col.apply_retention_mask(valid_locs).values result = cp.interp(index.to_cupy(), known_x, known_y) @@ -2065,7 +2065,7 @@ def indices_of(self, value: ScalarLike) -> NumericalColumn: return ( ColumnBase.from_range(range(len(self))) # type: ignore[return-value] .astype(SIZE_TYPE_DTYPE) - .apply_boolean_mask(mask) + .apply_retention_mask(mask) ) def _find_first_and_last(self, value: ScalarLike) -> tuple[int, int]: @@ -2393,16 +2393,24 @@ def as_string_column(self, dtype: DtypeObj) -> StringColumn: def as_decimal_column(self, dtype: DecimalDtype) -> DecimalColumn: raise NotImplementedError() - def apply_boolean_mask(self, mask: ColumnBase) -> ColumnBase: + def apply_retention_mask(self, mask: ColumnBase) -> ColumnBase: if mask.dtype.kind != "b": - raise ValueError("boolean_mask is not boolean type.") + raise ValueError("retention_mask is not boolean type.") return PylibcudfFunction( - plc.stream_compaction.apply_boolean_mask, + plc.stream_compaction.apply_retention_mask, same_dtype_policy, result_index=0, ).execute_with_args(ColumnList(self), mask) + def apply_boolean_mask(self, mask: ColumnBase) -> ColumnBase: + warnings.warn( + "apply_boolean_mask is deprecated; use apply_retention_mask instead", + DeprecationWarning, + stacklevel=2, + ) + return self.apply_retention_mask(mask) + def argsort( self, ascending: bool = True, diff --git a/python/cudf/cudf/core/column/datetime.py b/python/cudf/cudf/core/column/datetime.py index e1f174d1de3b..291fe275f1ae 100644 --- a/python/cudf/cudf/core/column/datetime.py +++ b/python/cudf/cudf/core/column/datetime.py @@ -958,11 +958,11 @@ def _find_ambiguous_and_nonexistent( # At the start of an ambiguous time period, Clock 1 (which has # been turned back) reads less than Clock 2: cond = clock_1 < clock_2 - ambiguous_begin = clock_1.apply_boolean_mask(cond) + ambiguous_begin = clock_1.apply_retention_mask(cond) # The end of an ambiguous time period is what Clock 2 reads at # the moment of transition: - ambiguous_end = clock_2.apply_boolean_mask(cond) + ambiguous_end = clock_2.apply_retention_mask(cond) ambiguous = self.label_bins( left_edge=ambiguous_begin, left_inclusive=True, @@ -973,11 +973,11 @@ def _find_ambiguous_and_nonexistent( # At the start of a non-existent time period, Clock 2 reads less # than Clock 1 (which has been turned forward): cond = clock_1 > clock_2 - nonexistent_begin = clock_2.apply_boolean_mask(cond) + nonexistent_begin = clock_2.apply_retention_mask(cond) # The end of the non-existent time period is what Clock 1 reads # at the moment of transition: - nonexistent_end = clock_1.apply_boolean_mask(cond) + nonexistent_end = clock_1.apply_retention_mask(cond) nonexistent = self.label_bins( left_edge=nonexistent_begin, left_inclusive=True, diff --git a/python/cudf/cudf/core/column/numerical.py b/python/cudf/cudf/core/column/numerical.py index 251514aa66ef..1ea27c51c680 100644 --- a/python/cudf/cudf/core/column/numerical.py +++ b/python/cudf/cudf/core/column/numerical.py @@ -1239,7 +1239,7 @@ def can_cast_safely(self, to_dtype: DtypeObj) -> bool: if self_dtype_numpy.kind == "f": # Exclude 'np.inf', '-np.inf' not_inf = (self != np.inf) & (self != -np.inf) - col = self.apply_boolean_mask(not_inf) + col = self.apply_retention_mask(not_inf) else: col = self diff --git a/python/cudf/cudf/core/column/string.py b/python/cudf/cudf/core/column/string.py index eb5d34a53637..160ce6429029 100644 --- a/python/cudf/cudf/core/column/string.py +++ b/python/cudf/cudf/core/column/string.py @@ -329,7 +329,7 @@ def strptime( "cuDF does not yet support timezone-aware datetimes" ) is_nat = self == "NaT" - without_nat = self.apply_boolean_mask(is_nat.unary_operator("not")) + without_nat = self.apply_retention_mask(is_nat.unary_operator("not")) char_counts = without_nat.count_characters() # type: ignore[attr-defined] if char_counts.distinct_count(dropna=True) != 1: # Unfortunately disables OK cases like: @@ -393,7 +393,7 @@ def strptime( return result_col def as_datetime_column(self, dtype: np.dtype) -> DatetimeColumn: - not_null = self.apply_boolean_mask(self.notnull()) + not_null = self.apply_retention_mask(self.notnull()) if len(not_null) == 0: # We should hit the self.null_count == len(self) condition # so format doesn't matter diff --git a/python/cudf/cudf/core/indexed_frame.py b/python/cudf/cudf/core/indexed_frame.py index fc24fc877f75..1b498e0b1f5f 100644 --- a/python/cudf/cudf/core/indexed_frame.py +++ b/python/cudf/cudf/core/indexed_frame.py @@ -4745,7 +4745,7 @@ def _apply_boolean_mask(self, boolean_mask: BooleanMask, keep_index=True): *cols, mask_col, ): - plc_table = plc.stream_compaction.apply_boolean_mask( + plc_table = plc.stream_compaction.apply_retention_mask( plc.Table([col.plc_column for col in cols]), mask_col.plc_column, ) @@ -4766,7 +4766,7 @@ def _apply_boolean_mask(self, boolean_mask: BooleanMask, keep_index=True): ): result.index._levels = self.index._levels result.index._codes = [ - code.apply_boolean_mask(boolean_mask.column) + code.apply_retention_mask(boolean_mask.column) for code in self.index._codes ] return result diff --git a/python/cudf/cudf/core/single_column_frame.py b/python/cudf/cudf/core/single_column_frame.py index 1f99abe16ee7..d32049243fe0 100644 --- a/python/cudf/cudf/core/single_column_frame.py +++ b/python/cudf/cudf/core/single_column_frame.py @@ -465,7 +465,7 @@ def _get_elements_from_column(self, arg) -> ScalarLike | ColumnBase: raise IndexError( f"Boolean mask has wrong length: {bn} not {n}" ) - return self._column.apply_boolean_mask(arg) + return self._column.apply_retention_mask(arg) raise NotImplementedError(f"Unknown indexer {type(arg)}") @_performance_tracking diff --git a/python/cudf/cudf/core/tools/datetimes.py b/python/cudf/cudf/core/tools/datetimes.py index d2edda4b4322..f8a6c789a43d 100644 --- a/python/cudf/cudf/core/tools/datetimes.py +++ b/python/cudf/cudf/core/tools/datetimes.py @@ -1127,7 +1127,7 @@ def date_range( # As mentioned in [1], this is a post processing step to trim extra # elements when `periods` is an estimated value. Only offset # specified with non fixed frequencies requires trimming. - res = res.apply_boolean_mask( + res = res.apply_retention_mask( (res <= end) if _is_increment_sequence else (res <= start) ) else: diff --git a/python/cudf/cudf/testing/testing.py b/python/cudf/cudf/testing/testing.py index 7429af2137fa..ee18e9d490f7 100644 --- a/python/cudf/cudf/testing/testing.py +++ b/python/cudf/cudf/testing/testing.py @@ -317,10 +317,10 @@ def assert_column_equal( ): # non-null values must be the same columns_equal = cp.allclose( - left.apply_boolean_mask( + left.apply_retention_mask( left.isnull().unary_operator("not") ).values, - right.apply_boolean_mask( + right.apply_retention_mask( right.isnull().unary_operator("not") ).values, ) diff --git a/python/cudf_polars/cudf_polars/containers/dataframe.py b/python/cudf_polars/cudf_polars/containers/dataframe.py index fc671bb0e2b0..3a17eab9c561 100644 --- a/python/cudf_polars/cudf_polars/containers/dataframe.py +++ b/python/cudf_polars/cudf_polars/containers/dataframe.py @@ -450,7 +450,7 @@ def filter(self, mask: Column) -> Self: ------- Filtered dataframe """ - table = plc.stream_compaction.apply_boolean_mask( + table = plc.stream_compaction.apply_retention_mask( self.table, mask.obj, stream=self.stream ) return ( diff --git a/python/cudf_polars/cudf_polars/dsl/expressions/selection.py b/python/cudf_polars/cudf_polars/dsl/expressions/selection.py index a10137af0d93..1b5c08e19ac2 100644 --- a/python/cudf_polars/cudf_polars/dsl/expressions/selection.py +++ b/python/cudf_polars/cudf_polars/dsl/expressions/selection.py @@ -81,7 +81,7 @@ def do_evaluate( values, mask = (child.evaluate(df, context=context) for child in self.children) # polars type-puns length-1 columns as scalars. values, mask = broadcast(values, mask, stream=df.stream) - table = plc.stream_compaction.apply_boolean_mask( + table = plc.stream_compaction.apply_retention_mask( plc.Table([values.obj]), mask.obj, stream=df.stream ) return Column(table.columns()[0], dtype=self.dtype).sorted_like(values) diff --git a/python/cudf_polars/cudf_polars/dsl/expressions/string.py b/python/cudf_polars/cudf_polars/dsl/expressions/string.py index 60d61c138139..a284527fa6bc 100644 --- a/python/cudf_polars/cudf_polars/dsl/expressions/string.py +++ b/python/cudf_polars/cudf_polars/dsl/expressions/string.py @@ -1086,7 +1086,7 @@ def do_evaluate( # Polars begins inference with the first non null value if plc_col.null_mask() is not None: boolmask = plc.unary.is_valid(plc_col, stream=df.stream) - table = plc.stream_compaction.apply_boolean_mask( + table = plc.stream_compaction.apply_retention_mask( plc.Table([plc_col]), boolmask, stream=df.stream ) filtered = table.columns()[0] diff --git a/python/cudf_polars/cudf_polars/dsl/expressions/unary.py b/python/cudf_polars/cudf_polars/dsl/expressions/unary.py index c7491fc0f2d8..b8a553f971d5 100644 --- a/python/cudf_polars/cudf_polars/dsl/expressions/unary.py +++ b/python/cudf_polars/cudf_polars/dsl/expressions/unary.py @@ -359,7 +359,7 @@ def _replace( ) result = column.obj if old.obj.null_count() != old.size: - nonnull_old, nonnull_new = plc.stream_compaction.apply_boolean_mask( + nonnull_old, nonnull_new = plc.stream_compaction.apply_retention_mask( plc.Table([old.obj, new.obj]), plc.unary.is_valid(old.obj, stream=df.stream), stream=df.stream, @@ -367,7 +367,7 @@ def _replace( result = plc.replace.find_and_replace_all( result, nonnull_old, nonnull_new, stream=df.stream ) - null_new = plc.stream_compaction.apply_boolean_mask( + null_new = plc.stream_compaction.apply_retention_mask( plc.Table([new.obj]), plc.unary.is_null(old.obj, stream=df.stream), stream=df.stream, @@ -524,7 +524,7 @@ def do_evaluate( stream=df.stream, ) return Column( - plc.stream_compaction.apply_boolean_mask( + plc.stream_compaction.apply_retention_mask( plc.Table([indices]), column.obj, stream=df.stream ).columns()[0], dtype=self.dtype, @@ -589,7 +589,7 @@ def do_evaluate( plc.DataType(plc.TypeId.BOOL8), stream=df.stream, ) - modes = plc.stream_compaction.apply_boolean_mask( + modes = plc.stream_compaction.apply_retention_mask( keys_table, mask, stream=df.stream ) return Column( @@ -1003,7 +1003,7 @@ def do_evaluate( plc.Scalar.from_py(1, self.dtype.plc_type, stream=df.stream), stream=df.stream, ) - matched = plc.stream_compaction.apply_boolean_mask( + matched = plc.stream_compaction.apply_retention_mask( plc.Table([indices]), mask, stream=df.stream ).columns()[0] if matched.size() == 0: diff --git a/python/pylibcudf/pylibcudf/libcudf/lists/stream_compaction.pxd b/python/pylibcudf/pylibcudf/libcudf/lists/stream_compaction.pxd index 7514f9d159ac..c2e7c767018e 100644 --- a/python/pylibcudf/pylibcudf/libcudf/lists/stream_compaction.pxd +++ b/python/pylibcudf/pylibcudf/libcudf/lists/stream_compaction.pxd @@ -12,6 +12,13 @@ from rmm.librmm.memory_resource cimport device_async_resource_ref cdef extern from "cudf/lists/stream_compaction.hpp" \ namespace "cudf::lists" nogil: + cdef unique_ptr[column] apply_retention_mask( + const lists_column_view& lists_column, + const lists_column_view& retention_mask, + cudaStream_t stream, + device_async_resource_ref mr + ) except +libcudf_exception_handler + cdef unique_ptr[column] apply_boolean_mask( const lists_column_view& lists_column, const lists_column_view& boolean_mask, diff --git a/python/pylibcudf/pylibcudf/libcudf/stream_compaction.pxd b/python/pylibcudf/pylibcudf/libcudf/stream_compaction.pxd index 9b5f6d287f33..35ba567b5368 100644 --- a/python/pylibcudf/pylibcudf/libcudf/stream_compaction.pxd +++ b/python/pylibcudf/pylibcudf/libcudf/stream_compaction.pxd @@ -41,6 +41,13 @@ cdef extern from "cudf/stream_compaction.hpp" namespace "cudf" nogil: device_async_resource_ref mr ) except +libcudf_exception_handler + cdef unique_ptr[table] apply_retention_mask( + table_view source_table, + column_view retention_mask, + cudaStream_t stream, + device_async_resource_ref mr + ) except +libcudf_exception_handler + cdef unique_ptr[table] apply_boolean_mask( table_view source_table, column_view boolean_mask, diff --git a/python/pylibcudf/pylibcudf/lists.pxd b/python/pylibcudf/pylibcudf/lists.pxd index 75db812de141..206bdfe6f86e 100644 --- a/python/pylibcudf/pylibcudf/lists.pxd +++ b/python/pylibcudf/pylibcudf/lists.pxd @@ -150,6 +150,13 @@ cpdef Column apply_boolean_mask( DeviceMemoryResource mr=*, ) +cpdef Column apply_retention_mask( + Column, + Column, + object stream = *, + DeviceMemoryResource mr=*, +) + cpdef Column apply_deletion_mask( Column, Column, diff --git a/python/pylibcudf/pylibcudf/lists.pyi b/python/pylibcudf/pylibcudf/lists.pyi index 6ff273458541..9d1af561e76a 100644 --- a/python/pylibcudf/pylibcudf/lists.pyi +++ b/python/pylibcudf/pylibcudf/lists.pyi @@ -131,6 +131,12 @@ def apply_boolean_mask( stream: CudaStreamLike | None = None, mr: DeviceMemoryResource | None = None, ) -> Column: ... +def apply_retention_mask( + input: Column, + retention_mask: Column, + stream: CudaStreamLike | None = None, + mr: DeviceMemoryResource | None = None, +) -> Column: ... def apply_deletion_mask( input: Column, deletion_mask: Column, diff --git a/python/pylibcudf/pylibcudf/lists.pyx b/python/pylibcudf/pylibcudf/lists.pyx index 930cacec73dc..b95a05ae370e 100644 --- a/python/pylibcudf/pylibcudf/lists.pyx +++ b/python/pylibcudf/pylibcudf/lists.pyx @@ -33,7 +33,7 @@ from pylibcudf.libcudf.lists.sorting cimport ( stable_sort_lists as cpp_stable_sort_lists, ) from pylibcudf.libcudf.lists.stream_compaction cimport ( - apply_boolean_mask as cpp_apply_boolean_mask, + apply_retention_mask as cpp_apply_retention_mask, apply_deletion_mask as cpp_apply_deletion_mask, distinct as cpp_distinct, ) @@ -59,6 +59,8 @@ from .column cimport Column, ListsColumnView from .scalar cimport Scalar from .table cimport Table from .utils cimport _get_stream, _get_memory_resource + +import warnings from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -70,6 +72,7 @@ __all__ = [ "DuplicateFindOption", "apply_boolean_mask", "apply_deletion_mask", + "apply_retention_mask", "concatenate_list_elements", "concatenate_rows", "contains", @@ -842,33 +845,33 @@ cpdef Column union_distinct( return Column.from_libcudf(move(c_result), _stream, mr) -cpdef Column apply_boolean_mask( +cpdef Column apply_retention_mask( Column input, - Column boolean_mask, + Column retention_mask, object stream: CudaStreamLike | None = None, DeviceMemoryResource mr=None, ): - """Filters elements in each row of the input lists column using a boolean mask + """Filters elements in each row of the input lists column using a retention mask. - For details, see :cpp:func:`apply_boolean_mask`. + For details, see :cpp:func:`apply_retention_mask`. Parameters ---------- input : Column The input column. - boolean_mask : Column - The boolean mask. + retention_mask : Column + The boolean mask whose true values retain input elements. stream : Stream | None CUDA stream on which to perform the operation. Returns ------- Column - A Column of filtered elements based upon the boolean mask. + A Column of filtered elements based upon the retention mask. """ cdef unique_ptr[column] c_result cdef ListsColumnView list_view = input.list_view() - cdef ListsColumnView mask_view = boolean_mask.list_view() + cdef ListsColumnView mask_view = retention_mask.list_view() cdef Stream _stream = _get_stream(stream) cdef cudaStream_t _cs = _stream.view().value() @@ -877,7 +880,7 @@ cpdef Column apply_boolean_mask( cdef lists_column_view c_list_view = list_view.view() cdef lists_column_view c_mask_view = mask_view.view() with nogil: - c_result = cpp_apply_boolean_mask( + c_result = cpp_apply_retention_mask( c_list_view, c_mask_view, _cs, @@ -886,6 +889,21 @@ cpdef Column apply_boolean_mask( return Column.from_libcudf(move(c_result), _stream, mr) +cpdef Column apply_boolean_mask( + Column input, + Column boolean_mask, + object stream: CudaStreamLike | None = None, + DeviceMemoryResource mr=None, +): + """Deprecated alias for :func:`apply_retention_mask`.""" + warnings.warn( + "apply_boolean_mask is deprecated; use apply_retention_mask instead", + DeprecationWarning, + stacklevel=2, + ) + return apply_retention_mask(input, boolean_mask, stream, mr) + + cpdef Column apply_deletion_mask( Column input, Column deletion_mask, diff --git a/python/pylibcudf/pylibcudf/stream_compaction.pxd b/python/pylibcudf/pylibcudf/stream_compaction.pxd index ffe36cebfbd5..d0bda9f93afe 100644 --- a/python/pylibcudf/pylibcudf/stream_compaction.pxd +++ b/python/pylibcudf/pylibcudf/stream_compaction.pxd @@ -37,6 +37,13 @@ cpdef Table apply_boolean_mask( DeviceMemoryResource mr = *, ) +cpdef Table apply_retention_mask( + Table source_table, + Column retention_mask, + object stream = *, + DeviceMemoryResource mr = *, +) + cpdef Table apply_deletion_mask( Table source_table, Column deletion_mask, diff --git a/python/pylibcudf/pylibcudf/stream_compaction.pyi b/python/pylibcudf/pylibcudf/stream_compaction.pyi index 76e669f89951..f3cca8222bbc 100644 --- a/python/pylibcudf/pylibcudf/stream_compaction.pyi +++ b/python/pylibcudf/pylibcudf/stream_compaction.pyi @@ -37,6 +37,12 @@ def apply_boolean_mask( stream: CudaStreamLike | None = None, mr: DeviceMemoryResource | None = None, ) -> Table: ... +def apply_retention_mask( + source_table: Table, + retention_mask: Column, + stream: CudaStreamLike | None = None, + mr: DeviceMemoryResource | None = None, +) -> Table: ... def apply_deletion_mask( source_table: Table, deletion_mask: Column, diff --git a/python/pylibcudf/pylibcudf/stream_compaction.pyx b/python/pylibcudf/pylibcudf/stream_compaction.pyx index 9d64484c9605..d76ca1a2e57b 100644 --- a/python/pylibcudf/pylibcudf/stream_compaction.pyx +++ b/python/pylibcudf/pylibcudf/stream_compaction.pyx @@ -26,6 +26,8 @@ from .column cimport Column from .expressions cimport Expression from .table cimport Table from .utils cimport _get_stream, _get_memory_resource + +import warnings from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -36,6 +38,7 @@ __all__ = [ "DuplicateKeepOption", "apply_boolean_mask", "apply_deletion_mask", + "apply_retention_mask", "distinct", "distinct_indices", "drop_nans", @@ -125,22 +128,22 @@ cpdef Table drop_nans( return Table.from_libcudf(move(c_result), _stream, mr) -cpdef Table apply_boolean_mask( +cpdef Table apply_retention_mask( Table source_table, - Column boolean_mask, + Column retention_mask, object stream: CudaStreamLike | None = None, DeviceMemoryResource mr=None, ): - """Filters out rows from the input table based on a boolean mask. + """Filters out rows from the input table based on a retention mask. - For details, see :cpp:func:`apply_boolean_mask`. + For details, see :cpp:func:`apply_retention_mask`. Parameters ---------- source_table : Table The input table to filter. - boolean_mask : Column - The boolean mask to apply to the input table. + retention_mask : Column + The boolean mask whose true values retain input rows. Returns ------- @@ -154,14 +157,29 @@ cpdef Table apply_boolean_mask( mr = _get_memory_resource(mr) cdef table_view c_source_table = source_table.view() - cdef column_view c_boolean_mask = boolean_mask.view() + cdef column_view c_retention_mask = retention_mask.view() with nogil: - c_result = cpp_stream_compaction.apply_boolean_mask( - c_source_table, c_boolean_mask, _cs, mr.get_mr() + c_result = cpp_stream_compaction.apply_retention_mask( + c_source_table, c_retention_mask, _cs, mr.get_mr() ) return Table.from_libcudf(move(c_result), _stream, mr) +cpdef Table apply_boolean_mask( + Table source_table, + Column boolean_mask, + object stream: CudaStreamLike | None = None, + DeviceMemoryResource mr=None, +): + """Deprecated alias for :func:`apply_retention_mask`.""" + warnings.warn( + "apply_boolean_mask is deprecated; use apply_retention_mask instead", + DeprecationWarning, + stacklevel=2, + ) + return apply_retention_mask(source_table, boolean_mask, stream, mr) + + cpdef Table apply_deletion_mask( Table source_table, Column deletion_mask, diff --git a/python/pylibcudf/tests/test_stream_compaction.py b/python/pylibcudf/tests/test_stream_compaction.py index 539642ddc8bf..b985031949d9 100644 --- a/python/pylibcudf/tests/test_stream_compaction.py +++ b/python/pylibcudf/tests/test_stream_compaction.py @@ -24,9 +24,9 @@ def lists_column_and_mask(): return pa_input, pa_mask -def test_lists_apply_boolean_mask(lists_column_and_mask): +def test_lists_apply_retention_mask(lists_column_and_mask): pa_input, pa_mask = lists_column_and_mask - result = plc.lists.apply_boolean_mask( + result = plc.lists.apply_retention_mask( plc.Column.from_arrow(pa_input), plc.Column.from_arrow(pa_mask) ) expected = pa.array([[0, 2], [4], [6, 8]], type=pa.list_(pa.int32())) @@ -42,7 +42,7 @@ def test_lists_apply_deletion_mask(lists_column_and_mask): assert_column_eq(expected, result) -def test_apply_boolean_mask(): +def test_apply_retention_mask(): pa_table = pa.table( { "a": pa.array([10, 40, 70, 5, 2, 10], type=pa.int32()), @@ -52,7 +52,7 @@ def test_apply_boolean_mask(): pa_mask = pa.array( [True, False, True, False, True, False], type=pa.bool_() ) - result = plc.stream_compaction.apply_boolean_mask( + result = plc.stream_compaction.apply_retention_mask( plc.Table.from_arrow(pa_table), plc.Column.from_arrow(pa_mask) ) expected = pa_table.filter(pa_mask) @@ -69,9 +69,9 @@ def test_apply_deletion_mask(): assert_table_eq(expected, result) -def test_apply_boolean_mask_zero_columns_preserves_num_rows(): +def test_apply_retention_mask_zero_columns_preserves_num_rows(): source = plc.Table([], num_rows=4) mask = plc.Column.from_arrow(pa.array([True, False, True, True])) - result = plc.stream_compaction.apply_boolean_mask(source, mask) + result = plc.stream_compaction.apply_retention_mask(source, mask) assert result.num_columns() == 0 assert result.num_rows() == 3 From 29e55deeacf7f933dce8b0ba7391d76e3da24394 Mon Sep 17 00:00:00 2001 From: Muhammad Haseeb Date: Thu, 20 Aug 2026 02:52:10 +0000 Subject: [PATCH 2/4] Style fix --- cpp/benchmarks/filter/minmax_filter.cpp | 2 +- cpp/benchmarks/stream_compaction/apply_boolean_mask.cpp | 2 +- cpp/include/cudf/detail/stream_compaction.hpp | 2 +- cpp/src/stream_compaction/apply_boolean_mask.cu | 2 +- cpp/tests/filter/filter_test.cpp | 2 +- cpp/tests/io/experimental/hybrid_scan_filters_test.cpp | 3 ++- cpp/tests/io/parquet_deletion_vectors_test.cpp | 3 ++- .../lists/stream_compaction/apply_boolean_mask_tests.cpp | 6 +++--- cpp/tests/streams/lists_test.cpp | 2 +- cpp/tests/streams/stream_compaction_test.cpp | 2 +- python/cudf/cudf/core/column/column.py | 2 +- python/cudf/cudf/core/column/string.py | 4 +++- .../pylibcudf/pylibcudf/libcudf/lists/stream_compaction.pxd | 2 +- python/pylibcudf/pylibcudf/libcudf/stream_compaction.pxd | 2 +- python/pylibcudf/pylibcudf/lists.pxd | 2 +- python/pylibcudf/pylibcudf/lists.pyi | 2 +- python/pylibcudf/pylibcudf/lists.pyx | 2 +- python/pylibcudf/pylibcudf/stream_compaction.pxd | 2 +- python/pylibcudf/pylibcudf/stream_compaction.pyi | 2 +- python/pylibcudf/pylibcudf/stream_compaction.pyx | 2 +- 20 files changed, 26 insertions(+), 22 deletions(-) diff --git a/cpp/benchmarks/filter/minmax_filter.cpp b/cpp/benchmarks/filter/minmax_filter.cpp index ebe4f8b16b8c..e7f3b01e8502 100644 --- a/cpp/benchmarks/filter/minmax_filter.cpp +++ b/cpp/benchmarks/filter/minmax_filter.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ diff --git a/cpp/benchmarks/stream_compaction/apply_boolean_mask.cpp b/cpp/benchmarks/stream_compaction/apply_boolean_mask.cpp index 07d269d30778..7ade80dc38f7 100644 --- a/cpp/benchmarks/stream_compaction/apply_boolean_mask.cpp +++ b/cpp/benchmarks/stream_compaction/apply_boolean_mask.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ diff --git a/cpp/include/cudf/detail/stream_compaction.hpp b/cpp/include/cudf/detail/stream_compaction.hpp index 4307f030ce76..87bcea4b898d 100644 --- a/cpp/include/cudf/detail/stream_compaction.hpp +++ b/cpp/include/cudf/detail/stream_compaction.hpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ diff --git a/cpp/src/stream_compaction/apply_boolean_mask.cu b/cpp/src/stream_compaction/apply_boolean_mask.cu index 623a4efaa041..a7b626d09c21 100644 --- a/cpp/src/stream_compaction/apply_boolean_mask.cu +++ b/cpp/src/stream_compaction/apply_boolean_mask.cu @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ diff --git a/cpp/tests/filter/filter_test.cpp b/cpp/tests/filter/filter_test.cpp index 6bb0c53ca2c3..e32ca4f13c47 100644 --- a/cpp/tests/filter/filter_test.cpp +++ b/cpp/tests/filter/filter_test.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2025-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ diff --git a/cpp/tests/io/experimental/hybrid_scan_filters_test.cpp b/cpp/tests/io/experimental/hybrid_scan_filters_test.cpp index e9cb54871e08..4585636a6f54 100644 --- a/cpp/tests/io/experimental/hybrid_scan_filters_test.cpp +++ b/cpp/tests/io/experimental/hybrid_scan_filters_test.cpp @@ -903,7 +903,8 @@ TEST_F(HybridScanFiltersTest, OffsetIndexOnlyDataPageMask) options, stream, mr); - auto const expected = cudf::apply_retention_mask(written_table->view(), row_mask_view, stream, mr); + auto const expected = + cudf::apply_retention_mask(written_table->view(), row_mask_view, stream, mr); CUDF_TEST_EXPECT_TABLES_EQUIVALENT(expected->view(), result.tbl->view()); // Without offset index, data-page pruning falls back to decoding all pages. diff --git a/cpp/tests/io/parquet_deletion_vectors_test.cpp b/cpp/tests/io/parquet_deletion_vectors_test.cpp index bb38c4077c20..b65b90bd5200 100644 --- a/cpp/tests/io/parquet_deletion_vectors_test.cpp +++ b/cpp/tests/io/parquet_deletion_vectors_test.cpp @@ -216,7 +216,8 @@ std::unique_ptr build_expected_table( cuda::counting_iterator(input_table_view.num_columns()), std::back_inserter(index_and_columns), [&](auto col_idx) { return input_table_view.column(col_idx); }); - return cudf::apply_retention_mask(cudf::table_view{index_and_columns}, row_mask_column, stream, mr); + return cudf::apply_retention_mask( + cudf::table_view{index_and_columns}, row_mask_column, stream, mr); } /** diff --git a/cpp/tests/lists/stream_compaction/apply_boolean_mask_tests.cpp b/cpp/tests/lists/stream_compaction/apply_boolean_mask_tests.cpp index 9229e45d9482..fb9cbade9db3 100644 --- a/cpp/tests/lists/stream_compaction/apply_boolean_mask_tests.cpp +++ b/cpp/tests/lists/stream_compaction/apply_boolean_mask_tests.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION. + * SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ #include @@ -151,8 +151,8 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, StructInput) // Unsliced. // The input should now look as follows: (String child dropped for brevity.) // Input: {[0, 1], [2], [3, 4, 5], [], [6, 7], [], [8, 9]} - auto const filter = filter_t{{1, 1}, {0}, {0, 1, 0}, {}, {1, 0}, {}, {0, 1}}; - auto const result = apply_retention_mask(lists_column_view{*input}, lists_column_view{filter}); + auto const filter = filter_t{{1, 1}, {0}, {0, 1, 0}, {}, {1, 0}, {}, {0, 1}}; + auto const result = apply_retention_mask(lists_column_view{*input}, lists_column_view{filter}); auto const expected = [] { auto child_num = fwcw{0, 1, 4, 6, 9}; auto child_str = strings{"0", "1", "4", "6", "9"}; diff --git a/cpp/tests/streams/lists_test.cpp b/cpp/tests/streams/lists_test.cpp index ec875515de0b..4dd973bb7449 100644 --- a/cpp/tests/streams/lists_test.cpp +++ b/cpp/tests/streams/lists_test.cpp @@ -1,5 +1,5 @@ /* - * 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 */ diff --git a/cpp/tests/streams/stream_compaction_test.cpp b/cpp/tests/streams/stream_compaction_test.cpp index af128f222719..a3355aab4f43 100644 --- a/cpp/tests/streams/stream_compaction_test.cpp +++ b/cpp/tests/streams/stream_compaction_test.cpp @@ -1,5 +1,5 @@ /* - * 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 */ diff --git a/python/cudf/cudf/core/column/column.py b/python/cudf/cudf/core/column/column.py index 9ee677575090..9fc965edd988 100644 --- a/python/cudf/cudf/core/column/column.py +++ b/python/cudf/cudf/core/column/column.py @@ -2406,7 +2406,7 @@ def apply_retention_mask(self, mask: ColumnBase) -> ColumnBase: def apply_boolean_mask(self, mask: ColumnBase) -> ColumnBase: warnings.warn( "apply_boolean_mask is deprecated; use apply_retention_mask instead", - DeprecationWarning, + FutureWarning, stacklevel=2, ) return self.apply_retention_mask(mask) diff --git a/python/cudf/cudf/core/column/string.py b/python/cudf/cudf/core/column/string.py index 160ce6429029..243936dbc532 100644 --- a/python/cudf/cudf/core/column/string.py +++ b/python/cudf/cudf/core/column/string.py @@ -329,7 +329,9 @@ def strptime( "cuDF does not yet support timezone-aware datetimes" ) is_nat = self == "NaT" - without_nat = self.apply_retention_mask(is_nat.unary_operator("not")) + without_nat = self.apply_retention_mask( + is_nat.unary_operator("not") + ) char_counts = without_nat.count_characters() # type: ignore[attr-defined] if char_counts.distinct_count(dropna=True) != 1: # Unfortunately disables OK cases like: diff --git a/python/pylibcudf/pylibcudf/libcudf/lists/stream_compaction.pxd b/python/pylibcudf/pylibcudf/libcudf/lists/stream_compaction.pxd index c2e7c767018e..6803cd078d64 100644 --- a/python/pylibcudf/pylibcudf/libcudf/lists/stream_compaction.pxd +++ b/python/pylibcudf/pylibcudf/libcudf/lists/stream_compaction.pxd @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION. +# SPDX-FileCopyrightText: Copyright (c) 2021-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 from libcpp.memory cimport unique_ptr from pylibcudf.exception_handler cimport libcudf_exception_handler diff --git a/python/pylibcudf/pylibcudf/libcudf/stream_compaction.pxd b/python/pylibcudf/pylibcudf/libcudf/stream_compaction.pxd index 35ba567b5368..b3b85822c908 100644 --- a/python/pylibcudf/pylibcudf/libcudf/stream_compaction.pxd +++ b/python/pylibcudf/pylibcudf/libcudf/stream_compaction.pxd @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION. +# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 from libcpp cimport bool from libcpp.memory cimport unique_ptr diff --git a/python/pylibcudf/pylibcudf/lists.pxd b/python/pylibcudf/pylibcudf/lists.pxd index 206bdfe6f86e..03f4ad96c1b0 100644 --- a/python/pylibcudf/pylibcudf/lists.pxd +++ b/python/pylibcudf/pylibcudf/lists.pxd @@ -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 from libcpp cimport bool diff --git a/python/pylibcudf/pylibcudf/lists.pyi b/python/pylibcudf/pylibcudf/lists.pyi index 9d1af561e76a..f04e135d159d 100644 --- a/python/pylibcudf/pylibcudf/lists.pyi +++ b/python/pylibcudf/pylibcudf/lists.pyi @@ -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 from enum import IntEnum diff --git a/python/pylibcudf/pylibcudf/lists.pyx b/python/pylibcudf/pylibcudf/lists.pyx index b95a05ae370e..4a39618a5ba7 100644 --- a/python/pylibcudf/pylibcudf/lists.pyx +++ b/python/pylibcudf/pylibcudf/lists.pyx @@ -898,7 +898,7 @@ cpdef Column apply_boolean_mask( """Deprecated alias for :func:`apply_retention_mask`.""" warnings.warn( "apply_boolean_mask is deprecated; use apply_retention_mask instead", - DeprecationWarning, + FutureWarning, stacklevel=2, ) return apply_retention_mask(input, boolean_mask, stream, mr) diff --git a/python/pylibcudf/pylibcudf/stream_compaction.pxd b/python/pylibcudf/pylibcudf/stream_compaction.pxd index d0bda9f93afe..da3200fa3db4 100644 --- a/python/pylibcudf/pylibcudf/stream_compaction.pxd +++ b/python/pylibcudf/pylibcudf/stream_compaction.pxd @@ -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 from pylibcudf.libcudf.stream_compaction cimport duplicate_keep_option diff --git a/python/pylibcudf/pylibcudf/stream_compaction.pyi b/python/pylibcudf/pylibcudf/stream_compaction.pyi index f3cca8222bbc..5a2a4d33ef8e 100644 --- a/python/pylibcudf/pylibcudf/stream_compaction.pyi +++ b/python/pylibcudf/pylibcudf/stream_compaction.pyi @@ -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 from enum import IntEnum diff --git a/python/pylibcudf/pylibcudf/stream_compaction.pyx b/python/pylibcudf/pylibcudf/stream_compaction.pyx index d76ca1a2e57b..ecf39a6582c0 100644 --- a/python/pylibcudf/pylibcudf/stream_compaction.pyx +++ b/python/pylibcudf/pylibcudf/stream_compaction.pyx @@ -174,7 +174,7 @@ cpdef Table apply_boolean_mask( """Deprecated alias for :func:`apply_retention_mask`.""" warnings.warn( "apply_boolean_mask is deprecated; use apply_retention_mask instead", - DeprecationWarning, + FutureWarning, stacklevel=2, ) return apply_retention_mask(source_table, boolean_mask, stream, mr) From e65f073390a924fef06ad8848649f6cda4990ec7 Mon Sep 17 00:00:00 2001 From: Muhammad Haseeb Date: Fri, 21 Aug 2026 00:22:25 +0000 Subject: [PATCH 3/4] Fix docs --- cpp/include/cudf/lists/stream_compaction.hpp | 6 +++++- cpp/include/cudf/stream_compaction.hpp | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cpp/include/cudf/lists/stream_compaction.hpp b/cpp/include/cudf/lists/stream_compaction.hpp index e5d10a84d487..7a84e04c3a0b 100644 --- a/cpp/include/cudf/lists/stream_compaction.hpp +++ b/cpp/include/cudf/lists/stream_compaction.hpp @@ -63,7 +63,11 @@ std::unique_ptr apply_retention_mask( * * @deprecated in release 26.10. Use `apply_retention_mask` instead. * - * @copydoc apply_retention_mask + * @param input The input list column view to be filtered. + * @param boolean_mask A nullable list of bools column used to filter `input` elements. + * @param stream CUDA stream used for device memory operations and kernel launches. + * @param mr Device memory resource used to allocate the returned column's device memory. + * @return List column of the same type as `input`, containing filtered list rows. */ [[deprecated("Use apply_retention_mask() instead")]] std::unique_ptr apply_boolean_mask( lists_column_view const& input, diff --git a/cpp/include/cudf/stream_compaction.hpp b/cpp/include/cudf/stream_compaction.hpp index 23cae65a33da..a22e301c6e5d 100644 --- a/cpp/include/cudf/stream_compaction.hpp +++ b/cpp/include/cudf/stream_compaction.hpp @@ -222,7 +222,13 @@ std::unique_ptr
apply_retention_mask( * * @deprecated in release 26.10. Use `apply_retention_mask` instead. * - * @copydoc apply_retention_mask + * @param[in] input The input table_view to filter. + * @param[in] boolean_mask A nullable column_view of type type_id::BOOL8 used + * as a mask to filter `input`. + * @param[in] stream CUDA stream used for device memory operations and kernel launches. + * @param[in] mr Device memory resource used to allocate the returned table's device memory. + * @return Table containing copies of all rows of @p input passing the filter defined by + * @p boolean_mask. */ [[deprecated("Use apply_retention_mask() instead")]] std::unique_ptr
apply_boolean_mask( table_view const& input, From 2c2a981fe1f47570537e8ca42f46be62f0131c69 Mon Sep 17 00:00:00 2001 From: Muhammad Haseeb Date: Tue, 25 Aug 2026 19:22:48 +0000 Subject: [PATCH 4/4] Address comments from @igorpeshansky --- cpp/CMakeLists.txt | 4 +-- cpp/benchmarks/CMakeLists.txt | 2 +- ...{apply_boolean_mask.cpp => apply_mask.cpp} | 0 cpp/include/cudf/detail/stream_compaction.hpp | 7 +++- .../cudf/lists/detail/stream_compaction.hpp | 7 +++- cpp/include/cudf/lists/stream_compaction.hpp | 7 ++-- cpp/include/cudf/stream_compaction.hpp | 6 ++-- .../parquet/experimental/hybrid_scan_impl.hpp | 2 +- .../{apply_boolean_mask.cu => apply_mask.cu} | 3 +- .../{apply_boolean_mask.cu => apply_mask.cu} | 3 +- cpp/tests/CMakeLists.txt | 4 +-- .../hybrid_scan_multifile_test.cpp | 2 +- cpp/tests/io/parquet_reader_test.cpp | 2 +- ...an_mask_tests.cpp => apply_mask_tests.cpp} | 20 +++++------ ...an_mask_tests.cpp => apply_mask_tests.cpp} | 0 cpp/tests/streams/lists_test.cpp | 2 +- cpp/tests/streams/stream_compaction_test.cpp | 2 +- .../main/java/ai/rapids/cudf/ColumnView.java | 35 ++++++++++++------- java/src/main/native/src/ColumnViewJni.cpp | 26 ++++++++++++++ .../java/ai/rapids/cudf/ColumnVectorTest.java | 4 +-- .../cudf/benchmarks/internal/bench_column.py | 6 ++-- python/pylibcudf/pylibcudf/lists.pxd | 4 +-- python/pylibcudf/pylibcudf/lists.pyi | 8 ++--- .../pylibcudf/pylibcudf/stream_compaction.pxd | 14 ++++---- .../pylibcudf/pylibcudf/stream_compaction.pyi | 8 ++--- 25 files changed, 115 insertions(+), 63 deletions(-) rename cpp/benchmarks/stream_compaction/{apply_boolean_mask.cpp => apply_mask.cpp} (100%) rename cpp/src/lists/stream_compaction/{apply_boolean_mask.cu => apply_mask.cu} (98%) rename cpp/src/stream_compaction/{apply_boolean_mask.cu => apply_mask.cu} (97%) rename cpp/tests/lists/stream_compaction/{apply_boolean_mask_tests.cpp => apply_mask_tests.cpp} (96%) rename cpp/tests/stream_compaction/{apply_boolean_mask_tests.cpp => apply_mask_tests.cpp} (100%) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 26b7ee68aad7..b1152af649ea 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -899,7 +899,7 @@ add_library( src/lists/segmented_sort.cu src/lists/sequences.cu src/lists/set_operations.cu - src/lists/stream_compaction/apply_boolean_mask.cu + src/lists/stream_compaction/apply_mask.cu src/lists/stream_compaction/distinct.cu src/lists/utilities.cu src/merge/merge.cu @@ -998,7 +998,7 @@ add_library( src/sort/stable_sort_column.cu src/sort/stable_sort.cu src/sort/top_k.cu - src/stream_compaction/apply_boolean_mask.cu + src/stream_compaction/apply_mask.cu src/stream_compaction/distinct.cu src/stream_compaction/distinct_helpers.cu src/stream_compaction/distinct_helpers_flat_nan_equal_any.cu diff --git a/cpp/benchmarks/CMakeLists.txt b/cpp/benchmarks/CMakeLists.txt index 192ed1b978b6..5782ca88be64 100644 --- a/cpp/benchmarks/CMakeLists.txt +++ b/cpp/benchmarks/CMakeLists.txt @@ -138,7 +138,7 @@ ConfigureNVBench(FILTER_NVBENCH filter/minmax_filter.cpp) # * stream_compaction benchmark ------------------------------------------------------------------- ConfigureNVBench( STREAM_COMPACTION_NVBENCH - stream_compaction/apply_boolean_mask.cpp + stream_compaction/apply_mask.cpp stream_compaction/distinct.cpp stream_compaction/stable_distinct.cpp stream_compaction/stream_compaction_common.cpp diff --git a/cpp/benchmarks/stream_compaction/apply_boolean_mask.cpp b/cpp/benchmarks/stream_compaction/apply_mask.cpp similarity index 100% rename from cpp/benchmarks/stream_compaction/apply_boolean_mask.cpp rename to cpp/benchmarks/stream_compaction/apply_mask.cpp diff --git a/cpp/include/cudf/detail/stream_compaction.hpp b/cpp/include/cudf/detail/stream_compaction.hpp index 8a686bc98b76..1e7b34587968 100644 --- a/cpp/include/cudf/detail/stream_compaction.hpp +++ b/cpp/include/cudf/detail/stream_compaction.hpp @@ -46,9 +46,14 @@ enum class mask_type : bool { }; /** - * @copydoc cudf::apply_retention_mask + * @brief Filters @p input using @p boolean_mask. * + * @param input The input table to filter + * @param boolean_mask A nullable BOOL8 column used to filter @p input * @param mask_kind Specifies how the boolean mask is treated (retentions or deletions) + * @param stream CUDA stream used for device memory operations and kernel launches + * @param mr Device memory resource used to allocate the returned table's device memory + * @return A table containing the rows of @p input selected by @p boolean_mask and @p mask_kind */ std::unique_ptr
apply_mask(table_view const& input, column_view const& boolean_mask, diff --git a/cpp/include/cudf/lists/detail/stream_compaction.hpp b/cpp/include/cudf/lists/detail/stream_compaction.hpp index 48b759ce197c..a55ab6844caa 100644 --- a/cpp/include/cudf/lists/detail/stream_compaction.hpp +++ b/cpp/include/cudf/lists/detail/stream_compaction.hpp @@ -14,9 +14,14 @@ namespace cudf { namespace lists::detail { /** - * @copydoc cudf::lists::apply_retention_mask + * @brief Filters elements in each row of @p input using @p boolean_mask. * + * @param input The input lists column to filter + * @param boolean_mask A nullable lists-of-bools column used to filter @p input * @param mask_kind Specifies how the boolean mask is treated (retentions or deletions) + * @param stream CUDA stream used for device memory operations and kernel launches + * @param mr Device memory resource used to allocate the returned column's device memory + * @return A lists column containing the elements selected by @p boolean_mask and @p mask_kind */ std::unique_ptr apply_mask(lists_column_view const& input, lists_column_view const& boolean_mask, diff --git a/cpp/include/cudf/lists/stream_compaction.hpp b/cpp/include/cudf/lists/stream_compaction.hpp index 7a84e04c3a0b..3134b5779f1e 100644 --- a/cpp/include/cudf/lists/stream_compaction.hpp +++ b/cpp/include/cudf/lists/stream_compaction.hpp @@ -42,13 +42,16 @@ namespace lists { * `true`. * An output row is invalid only if the input row is invalid. * + * @note @p input and @p retention_mask must have the same number of rows. The output column has the + * same number of rows as the input column. + * * @throws cudf::logic_error if @p retention_mask is not a "lists of bools" column - * @throws cudf::logic_error if @p input` and @p retention_mask have different number of rows + * @throws cudf::logic_error if @p input and @p retention_mask have different number of rows * * @param input The input list column view to be filtered * @param retention_mask A nullable list of bools column used to filter `input` elements * @param stream CUDA stream used for device memory operations and kernel launches - * @param mr Device memory resource used to allocate the returned table's device memory + * @param mr Device memory resource used to allocate the returned column's device memory * @return List column of the same type as `input`, containing filtered list rows */ std::unique_ptr apply_retention_mask( diff --git a/cpp/include/cudf/stream_compaction.hpp b/cpp/include/cudf/stream_compaction.hpp index a8f62fae1670..e9b16aeab0e4 100644 --- a/cpp/include/cudf/stream_compaction.hpp +++ b/cpp/include/cudf/stream_compaction.hpp @@ -197,10 +197,10 @@ std::unique_ptr
drop_nans( * if the corresponding element `i` in the mask is non-null and `true`. * This operation is stable: the input order is preserved. * - * @note if @p input.num_rows() is zero, there is no error, and an empty table - * is returned. + * @note If @p retention_mask is empty, or @p input has zero rows, an empty table is returned. * - * @throws cudf::logic_error if `input.num_rows() != retention_mask.size()`. + * @throws cudf::logic_error if non-empty @p input has different number of rows than @p + * retention_mask. * @throws cudf::logic_error if @p retention_mask is not `type_id::BOOL8` type. * * @param[in] input The input table_view to filter diff --git a/cpp/src/io/parquet/experimental/hybrid_scan_impl.hpp b/cpp/src/io/parquet/experimental/hybrid_scan_impl.hpp index 8d8f693e58ed..0f2930925d99 100644 --- a/cpp/src/io/parquet/experimental/hybrid_scan_impl.hpp +++ b/cpp/src/io/parquet/experimental/hybrid_scan_impl.hpp @@ -590,7 +590,7 @@ class hybrid_scan_reader_impl : public parquet::detail::reader_impl { * and only if in_row_mask[i] is valid and true * * Updates the output row mask to reflect the final valid and surviving rows from the input row - * mask. This is inline with the masking behavior of cudf::detail::apply_mask + * mask. This is inline with the masking behavior of cudf::apply_retention_mask. * * @param in_row_mask Input row mask column * @param out_row_mask Output row mask column diff --git a/cpp/src/lists/stream_compaction/apply_boolean_mask.cu b/cpp/src/lists/stream_compaction/apply_mask.cu similarity index 98% rename from cpp/src/lists/stream_compaction/apply_boolean_mask.cu rename to cpp/src/lists/stream_compaction/apply_mask.cu index eefe135f233a..d0f7ad6b690c 100644 --- a/cpp/src/lists/stream_compaction/apply_boolean_mask.cu +++ b/cpp/src/lists/stream_compaction/apply_mask.cu @@ -117,7 +117,8 @@ std::unique_ptr apply_boolean_mask(lists_column_view const& input, cuda::stream_ref stream, rmm::device_async_resource_ref mr) { - return apply_retention_mask(input, boolean_mask, stream, mr); + CUDF_FUNC_RANGE(); + return detail::apply_mask(input, boolean_mask, cudf::detail::mask_type::RETENTION, stream, mr); } std::unique_ptr apply_deletion_mask(lists_column_view const& input, diff --git a/cpp/src/stream_compaction/apply_boolean_mask.cu b/cpp/src/stream_compaction/apply_mask.cu similarity index 97% rename from cpp/src/stream_compaction/apply_boolean_mask.cu rename to cpp/src/stream_compaction/apply_mask.cu index dbd5f57e24e4..f06b20b7735c 100644 --- a/cpp/src/stream_compaction/apply_boolean_mask.cu +++ b/cpp/src/stream_compaction/apply_mask.cu @@ -110,7 +110,8 @@ std::unique_ptr
apply_boolean_mask(table_view const& input, cuda::stream_ref stream, rmm::device_async_resource_ref mr) { - return apply_retention_mask(input, boolean_mask, stream, mr); + CUDF_FUNC_RANGE(); + return detail::apply_mask(input, boolean_mask, detail::mask_type::RETENTION, stream, mr); } std::unique_ptr
apply_deletion_mask(table_view const& input, diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index d268ed76d3b2..761f690a110e 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -513,7 +513,7 @@ ConfigureTest( # * stream compaction tests ----------------------------------------------------------------------- ConfigureTest( STREAM_COMPACTION_TEST - stream_compaction/apply_boolean_mask_tests.cpp + stream_compaction/apply_mask_tests.cpp stream_compaction/distinct_tests.cpp stream_compaction/drop_nans_tests.cpp stream_compaction/drop_nulls_tests.cpp @@ -738,7 +738,7 @@ ConfigureTest( lists/set_operations/intersect_distinct_tests.cpp lists/set_operations/union_distinct_tests.cpp lists/sort_lists_tests.cpp - lists/stream_compaction/apply_boolean_mask_tests.cpp + lists/stream_compaction/apply_mask_tests.cpp lists/stream_compaction/distinct_tests.cpp GPUS 1 PERCENT 70 diff --git a/cpp/tests/io/experimental/hybrid_scan_multifile_test.cpp b/cpp/tests/io/experimental/hybrid_scan_multifile_test.cpp index 47c8164468b6..47f26e0dffb8 100644 --- a/cpp/tests/io/experimental/hybrid_scan_multifile_test.cpp +++ b/cpp/tests/io/experimental/hybrid_scan_multifile_test.cpp @@ -353,7 +353,7 @@ TEST_F(HybridScanMultifileTest, SparseDictionaryEncodedPages) auto const input = cudf::concatenate(std::vector(num_sources, payload_table), stream, mr); - auto const expected = cudf::apply_boolean_mask(input->view(), row_mask, stream, mr); + auto const expected = cudf::apply_retention_mask(input->view(), row_mask, stream, mr); CUDF_TEST_EXPECT_TABLES_EQUIVALENT(expected->view(), result.tbl->view()); } diff --git a/cpp/tests/io/parquet_reader_test.cpp b/cpp/tests/io/parquet_reader_test.cpp index 0c305b93ce7d..c2b17caf7e96 100644 --- a/cpp/tests/io/parquet_reader_test.cpp +++ b/cpp/tests/io/parquet_reader_test.cpp @@ -2383,7 +2383,7 @@ TEST_F(ParquetReaderTest, FilterNegationPushdown) std::optional expected_row_groups = std::nullopt) { auto predicate = cudf::compute_column(written_table, filter); - auto expected = cudf::apply_boolean_mask(written_table, *predicate); + auto expected = cudf::apply_retention_mask(written_table, *predicate); cudf::io::parquet_reader_options const read_opts = cudf::io::parquet_reader_options::builder(cudf::io::source_info{filepath}).filter(filter); diff --git a/cpp/tests/lists/stream_compaction/apply_boolean_mask_tests.cpp b/cpp/tests/lists/stream_compaction/apply_mask_tests.cpp similarity index 96% rename from cpp/tests/lists/stream_compaction/apply_boolean_mask_tests.cpp rename to cpp/tests/lists/stream_compaction/apply_mask_tests.cpp index fb9cbade9db3..5facca374465 100644 --- a/cpp/tests/lists/stream_compaction/apply_boolean_mask_tests.cpp +++ b/cpp/tests/lists/stream_compaction/apply_mask_tests.cpp @@ -28,14 +28,14 @@ using strings = strings_column_wrapper; auto constexpr X = int32_t{0}; // Placeholder for NULL. -struct ApplyBooleanMaskTest : public BaseFixture {}; +struct ApplyRetentionMaskTest : public BaseFixture {}; template -struct ApplyBooleanMaskTypedTest : ApplyBooleanMaskTest {}; +struct ApplyRetentionMaskTypedTest : ApplyRetentionMaskTest {}; -TYPED_TEST_SUITE(ApplyBooleanMaskTypedTest, cudf::test::NumericTypes); +TYPED_TEST_SUITE(ApplyRetentionMaskTypedTest, cudf::test::NumericTypes); -TYPED_TEST(ApplyBooleanMaskTypedTest, StraightLine) +TYPED_TEST(ApplyRetentionMaskTypedTest, StraightLine) { using T = TypeParam; auto input = lists{{0, 1, 2, 3}, {4, 5}, {6, 7, 8, 9}, {0, 1}, {2, 3, 4, 5}, {6, 7}}.release(); @@ -58,7 +58,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, StraightLine) } } -TYPED_TEST(ApplyBooleanMaskTypedTest, NullElementsInTheListRows) +TYPED_TEST(ApplyRetentionMaskTypedTest, NullElementsInTheListRows) { using T = TypeParam; auto input = @@ -95,7 +95,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, NullElementsInTheListRows) } } -TYPED_TEST(ApplyBooleanMaskTypedTest, NullListRowsInTheInputColumn) +TYPED_TEST(ApplyRetentionMaskTypedTest, NullListRowsInTheInputColumn) { using T = TypeParam; auto input = @@ -129,7 +129,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, NullListRowsInTheInputColumn) } } -TYPED_TEST(ApplyBooleanMaskTypedTest, StructInput) +TYPED_TEST(ApplyRetentionMaskTypedTest, StructInput) { using T = TypeParam; using fwcw = fwcw; @@ -191,7 +191,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, StructInput) } } -TYPED_TEST(ApplyBooleanMaskTypedTest, NullsInBooleanMask) +TYPED_TEST(ApplyRetentionMaskTypedTest, NullsInBooleanMask) { using T = TypeParam; auto input = lists{{10, 20, 30}, {40, 50}, {60, 70, 80, 90}}; @@ -206,7 +206,7 @@ TYPED_TEST(ApplyBooleanMaskTypedTest, NullsInBooleanMask) CUDF_TEST_EXPECT_COLUMNS_EQUAL(*filtered, expected); } -TEST_F(ApplyBooleanMaskTest, Trivial) +TEST_F(ApplyRetentionMaskTest, Trivial) { auto const input = lists{}; auto const filter = filter_t{}; @@ -214,7 +214,7 @@ TEST_F(ApplyBooleanMaskTest, Trivial) CUDF_TEST_EXPECT_COLUMNS_EQUAL(*result, lists{}); } -TEST_F(ApplyBooleanMaskTest, Failure) +TEST_F(ApplyRetentionMaskTest, Failure) { { // Invalid mask type. diff --git a/cpp/tests/stream_compaction/apply_boolean_mask_tests.cpp b/cpp/tests/stream_compaction/apply_mask_tests.cpp similarity index 100% rename from cpp/tests/stream_compaction/apply_boolean_mask_tests.cpp rename to cpp/tests/stream_compaction/apply_mask_tests.cpp diff --git a/cpp/tests/streams/lists_test.cpp b/cpp/tests/streams/lists_test.cpp index 4dd973bb7449..ded383936e0b 100644 --- a/cpp/tests/streams/lists_test.cpp +++ b/cpp/tests/streams/lists_test.cpp @@ -144,7 +144,7 @@ TEST_F(ListTest, StableSortLists) list_col, cudf::order::DESCENDING, cudf::null_order::AFTER, cudf::test::get_default_stream()); } -TEST_F(ListTest, ApplyBooleanMask) +TEST_F(ListTest, ApplyRetentionMask) { cudf::test::lists_column_wrapper list_col{{0, 1}, {2, 3, 7, 8}, {4, 5}}; cudf::test::lists_column_wrapper boolean_mask{ diff --git a/cpp/tests/streams/stream_compaction_test.cpp b/cpp/tests/streams/stream_compaction_test.cpp index a3355aab4f43..5078abc18c7a 100644 --- a/cpp/tests/streams/stream_compaction_test.cpp +++ b/cpp/tests/streams/stream_compaction_test.cpp @@ -343,7 +343,7 @@ TEST_F(StreamCompactionTest, Distinct) } } -TEST_F(StreamCompactionTest, ApplyBooleanMask) +TEST_F(StreamCompactionTest, ApplyRetentionMask) { auto const col = int32s_col{ 9668, 9590, 9526, 9205, 9434, 9347, 9160, 9569, 9143, 9807, 9606, 9446, 9279, 9822, 9691}; diff --git a/java/src/main/java/ai/rapids/cudf/ColumnView.java b/java/src/main/java/ai/rapids/cudf/ColumnView.java index 06f1963f11dd..0200fd377eec 100644 --- a/java/src/main/java/ai/rapids/cudf/ColumnView.java +++ b/java/src/main/java/ai/rapids/cudf/ColumnView.java @@ -4442,34 +4442,42 @@ public final Scalar getScalarElement(int index) { } /** - * Filters elements in each row of this LIST column using `booleanMaskView` + * Filters elements in each row of this LIST column using `retentionMaskView` * LIST of booleans as a mask. *

* Given a list-of-bools column, the function produces * a new `LIST` column of the same type as this column, where each element is copied - * from the row *only* if the corresponding `boolean_mask` is non-null and `true`. + * from the row *only* if the corresponding `retention_mask` is non-null and `true`. *

* E.g. * column = { {0,1,2}, {3,4}, {5,6,7}, {8,9} }; - * boolean_mask = { {0,1,1}, {1,0}, {1,1,1}, {0,0} }; + * retention_mask = { {0,1,1}, {1,0}, {1,1,1}, {0,0} }; * results = { {1,2}, {3}, {5,6,7}, {} }; *

- * This column and `boolean_mask` must have the same number of rows. + * This column and `retention_mask` must have the same number of rows. * The output column has the same number of rows as this column. * An element is copied to an output row *only* - * if the corresponding boolean_mask element is `true`. + * if the corresponding retention_mask element is `true`. * An output row is invalid only if the row is invalid. * - * @param booleanMaskView A nullable list of bools column used to filter elements in this column + * @param retentionMaskView A nullable list of bools column used to filter elements in this column * @return List column of the same type as this column, containing filtered list rows - * @throws CudfException if `boolean_mask` is not a "lists of bools" column - * @throws CudfException if this column and `boolean_mask` have different number of rows + * @throws CudfException if `retention_mask` is not a "lists of bools" column + * @throws CudfException if this column and `retention_mask` have different number of rows */ - public final ColumnVector applyBooleanMask(ColumnView booleanMaskView) { + public final ColumnVector applyRetentionMask(ColumnView retentionMaskView) { assert (getType().equals(DType.LIST)); - assert (booleanMaskView.getType().equals(DType.LIST)); - assert (getRowCount() == booleanMaskView.getRowCount()); - return new ColumnVector(applyBooleanMask(getNativeView(), booleanMaskView.getNativeView())); + assert (retentionMaskView.getType().equals(DType.LIST)); + assert (getRowCount() == retentionMaskView.getRowCount()); + return new ColumnVector(applyRetentionMask(getNativeView(), retentionMaskView.getNativeView())); + } + + /** + * @deprecated Use {@link #applyRetentionMask(ColumnView)} instead. + */ + @Deprecated + public final ColumnVector applyBooleanMask(ColumnView booleanMaskView) { + return applyRetentionMask(booleanMaskView); } /** @@ -5249,6 +5257,9 @@ static native long makeCudfColumnView(int type, int scale, long data, long dataS static native long generateListOffsets(long handle) throws CudfException; + static native long applyRetentionMask(long arrayColumnView, long retentionMaskHandle) + throws CudfException; + static native long applyBooleanMask(long arrayColumnView, long booleanMaskHandle) throws CudfException; static native boolean hasNonEmptyNulls(long handle) throws CudfException; diff --git a/java/src/main/native/src/ColumnViewJni.cpp b/java/src/main/native/src/ColumnViewJni.cpp index 5aa5cb2f780a..94402967f2b7 100644 --- a/java/src/main/native/src/ColumnViewJni.cpp +++ b/java/src/main/native/src/ColumnViewJni.cpp @@ -2956,6 +2956,29 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_repeatStringsWithColumnRe JNI_CATCH(env, 0); } +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_applyRetentionMask( + JNIEnv* env, jclass, jlong list_column_handle, jlong retention_mask_list_column_handle) +{ + JNI_NULL_CHECK(env, list_column_handle, "list handle is null", 0); + JNI_NULL_CHECK(env, retention_mask_list_column_handle, "retention mask handle is null", 0); + JNI_TRY + { + cudf::jni::auto_set_device(env); + + cudf::column_view const* list_column = + reinterpret_cast(list_column_handle); + cudf::lists_column_view const list_view = cudf::lists_column_view(*list_column); + + cudf::column_view const* retention_mask_list_column = + reinterpret_cast(retention_mask_list_column_handle); + cudf::lists_column_view const retention_mask_list_view = + cudf::lists_column_view(*retention_mask_list_column); + + return release_as_jlong(cudf::lists::apply_retention_mask(list_view, retention_mask_list_view)); + } + JNI_CATCH(env, 0); +} + JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_applyBooleanMask( JNIEnv* env, jclass, jlong list_column_handle, jlong boolean_mask_list_column_handle) { @@ -2974,7 +2997,10 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_applyBooleanMask( cudf::lists_column_view const boolean_mask_list_view = cudf::lists_column_view(*boolean_mask_list_column); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" return release_as_jlong(cudf::lists::apply_boolean_mask(list_view, boolean_mask_list_view)); +#pragma GCC diagnostic pop } JNI_CATCH(env, 0); } diff --git a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java index d877c5c193e8..d5aa53be7f9d 100644 --- a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java +++ b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java @@ -6927,8 +6927,8 @@ void testApplyBooleanMaskFromListOfStructure() { ); ColumnVector listOfBoolCv = boolCv.makeListFromOffsets(5, offsetsCv); - // apply boolean mask - ColumnVector actualCv = listOfStructCv.applyBooleanMask(listOfBoolCv); + // apply retention mask + ColumnVector actualCv = listOfStructCv.applyRetentionMask(listOfBoolCv); ColumnVector expectedKeyCv = ColumnVector.fromBoxedInts( 11, // list1 diff --git a/python/cudf/benchmarks/internal/bench_column.py b/python/cudf/benchmarks/internal/bench_column.py index bd5c0da2cae4..c7579b1f565e 100644 --- a/python/cudf/benchmarks/internal/bench_column.py +++ b/python/cudf/benchmarks/internal/bench_column.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: Copyright (c) 2022-2024, NVIDIA CORPORATION. +# SPDX-FileCopyrightText: Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 """Benchmarks of Column methods.""" @@ -13,9 +13,9 @@ @benchmark_with_object(cls="column", dtype="float") -def bench_apply_boolean_mask(benchmark, column): +def bench_apply_retention_mask(benchmark, column): mask = make_boolean_mask_column(column.size) - benchmark(column.apply_boolean_mask, mask) + benchmark(column.apply_retention_mask, mask) @benchmark_with_object(cls="column", dtype="float") diff --git a/python/pylibcudf/pylibcudf/lists.pxd b/python/pylibcudf/pylibcudf/lists.pxd index 03f4ad96c1b0..a9083d8f1b7d 100644 --- a/python/pylibcudf/pylibcudf/lists.pxd +++ b/python/pylibcudf/pylibcudf/lists.pxd @@ -143,14 +143,14 @@ cpdef Column union_distinct( DeviceMemoryResource mr=*, ) -cpdef Column apply_boolean_mask( +cpdef Column apply_retention_mask( Column, Column, object stream = *, DeviceMemoryResource mr=*, ) -cpdef Column apply_retention_mask( +cpdef Column apply_boolean_mask( Column, Column, object stream = *, diff --git a/python/pylibcudf/pylibcudf/lists.pyi b/python/pylibcudf/pylibcudf/lists.pyi index f04e135d159d..84f2b218a56e 100644 --- a/python/pylibcudf/pylibcudf/lists.pyi +++ b/python/pylibcudf/pylibcudf/lists.pyi @@ -125,15 +125,15 @@ def union_distinct( stream: CudaStreamLike | None = None, mr: DeviceMemoryResource | None = None, ) -> Column: ... -def apply_boolean_mask( +def apply_retention_mask( input: Column, - boolean_mask: Column, + retention_mask: Column, stream: CudaStreamLike | None = None, mr: DeviceMemoryResource | None = None, ) -> Column: ... -def apply_retention_mask( +def apply_boolean_mask( input: Column, - retention_mask: Column, + boolean_mask: Column, stream: CudaStreamLike | None = None, mr: DeviceMemoryResource | None = None, ) -> Column: ... diff --git a/python/pylibcudf/pylibcudf/stream_compaction.pxd b/python/pylibcudf/pylibcudf/stream_compaction.pxd index da3200fa3db4..705eea5e0a1f 100644 --- a/python/pylibcudf/pylibcudf/stream_compaction.pxd +++ b/python/pylibcudf/pylibcudf/stream_compaction.pxd @@ -30,18 +30,18 @@ cpdef Table drop_nans( DeviceMemoryResource mr = *, ) -cpdef Table apply_boolean_mask( +cpdef Table apply_retention_mask( Table source_table, - Column boolean_mask, + Column retention_mask, object stream = *, DeviceMemoryResource mr = *, ) -cpdef Table apply_retention_mask( - Table source_table, - Column retention_mask, - object stream = *, - DeviceMemoryResource mr = *, +cpdef Table apply_boolean_mask( + Table source_table, + Column boolean_mask, + object stream = *, + DeviceMemoryResource mr = *, ) cpdef Table apply_deletion_mask( diff --git a/python/pylibcudf/pylibcudf/stream_compaction.pyi b/python/pylibcudf/pylibcudf/stream_compaction.pyi index 5a2a4d33ef8e..617cfce17e4d 100644 --- a/python/pylibcudf/pylibcudf/stream_compaction.pyi +++ b/python/pylibcudf/pylibcudf/stream_compaction.pyi @@ -31,15 +31,15 @@ def drop_nans( stream: CudaStreamLike | None = None, mr: DeviceMemoryResource | None = None, ) -> Table: ... -def apply_boolean_mask( +def apply_retention_mask( source_table: Table, - boolean_mask: Column, + retention_mask: Column, stream: CudaStreamLike | None = None, mr: DeviceMemoryResource | None = None, ) -> Table: ... -def apply_retention_mask( +def apply_boolean_mask( source_table: Table, - retention_mask: Column, + boolean_mask: Column, stream: CudaStreamLike | None = None, mr: DeviceMemoryResource | None = None, ) -> Table: ...