From c10966cc3847ca9837ddc7ce5df9c4d9b7c743d8 Mon Sep 17 00:00:00 2001 From: Alfred Xu Date: Thu, 2 Dec 2021 18:48:03 +0800 Subject: [PATCH] Fix make_empty_scalar_like on list_type (#9759) Fixes #9758 In `make_empty_scalar_like`, we create list scalar with the list column itself, which is wrong. The correct way is with the child of list column. Authors: - Alfred Xu (https://github.com/sperlingxx) Approvers: - Nghia Truong (https://github.com/ttnghia) - Devavret Makkar (https://github.com/devavret) URL: https://github.com/rapidsai/cudf/pull/9759 --- cpp/src/scalar/scalar_factories.cpp | 7 +++++-- cpp/tests/reductions/reduction_tests.cpp | 8 ++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cpp/src/scalar/scalar_factories.cpp b/cpp/src/scalar/scalar_factories.cpp index d2876435780..c18b57d220f 100644 --- a/cpp/src/scalar/scalar_factories.cpp +++ b/cpp/src/scalar/scalar_factories.cpp @@ -21,6 +21,7 @@ #include #include +#include #include namespace cudf { @@ -184,10 +185,12 @@ std::unique_ptr make_empty_scalar_like(column_view const& column, { std::unique_ptr result; switch (column.type().id()) { - case type_id::LIST: - result = make_list_scalar(empty_like(column)->view(), stream, mr); + case type_id::LIST: { + auto const empty_child = empty_like(lists_column_view(column).child()); + result = make_list_scalar(empty_child->view(), stream, mr); result->set_valid_async(false, stream); break; + } case type_id::STRUCT: // The input column must have at least 1 row to extract a scalar (row) from it. result = detail::get_element(column, 0, stream, mr); diff --git a/cpp/tests/reductions/reduction_tests.cpp b/cpp/tests/reductions/reduction_tests.cpp index d8ee8f9d08d..e138cd6f68e 100644 --- a/cpp/tests/reductions/reduction_tests.cpp +++ b/cpp/tests/reductions/reduction_tests.cpp @@ -1961,7 +1961,11 @@ struct ListReductionTest : public cudf::test::BaseFixture { cudf::reduce(input_data, agg, cudf::data_type(cudf::type_id::LIST)); auto list_result = dynamic_cast(result.get()); EXPECT_EQ(is_valid, list_result->is_valid()); - if (is_valid) { CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_value, list_result->view()); } + if (is_valid) { + CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected_value, list_result->view()); + } else { + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(expected_value, list_result->view()); + } }; if (succeeded_condition) { @@ -2047,7 +2051,7 @@ TEST_F(ListReductionTest, NonValidListReductionNthElement) // test against empty input this->reduction_test(LCW{}, - ElementCol{{0}, {0}}, // expected_value, + ElementCol{}, // expected_value, true, false, cudf::make_nth_element_aggregation(0, cudf::null_policy::INCLUDE));