Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix make_empty_scalar_like on list_type #9759

Merged
merged 2 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cpp/src/scalar/scalar_factories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <cudf/utilities/type_dispatcher.hpp>

#include <cudf/detail/copy.hpp>
#include <cudf/lists/lists_column_view.hpp>
#include <rmm/cuda_stream_view.hpp>

namespace cudf {
Expand Down Expand Up @@ -184,10 +185,12 @@ std::unique_ptr<scalar> make_empty_scalar_like(column_view const& column,
{
std::unique_ptr<scalar> 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);
Expand Down
8 changes: 6 additions & 2 deletions cpp/tests/reductions/reduction_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<cudf::list_scalar*>(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) {
Expand Down Expand Up @@ -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));
Expand Down