Skip to content

Commit

Permalink
Allow empty input table in ast compute_column (#13245)
Browse files Browse the repository at this point in the history
If the input table is empty we can still produce an output of
appropriate type by letting the parser run and inferring types.
In this case though, we do not want to actually run a kernel,
since we would try and launch with zero blocks which is not
allowed.

Closes #13236.

Authors:
  - Lawrence Mitchell (https://github.com/wence-)
  - Vukasin Milovanovic (https://github.com/vuule)

Approvers:
  - Vukasin Milovanovic (https://github.com/vuule)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #13245
  • Loading branch information
wence- committed May 2, 2023
1 parent ef4ebce commit dfacb95
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cpp/src/transform/compute_column.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020-2022, NVIDIA CORPORATION.
* Copyright (c) 2020-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -97,6 +97,7 @@ std::unique_ptr<column> compute_column(table_view const& table,

auto output_column = cudf::make_fixed_width_column(
parser.output_type(), table.num_rows(), output_column_mask_state, stream, mr);
if (table.num_rows() == 0) { return output_column; }
auto mutable_output_device =
cudf::mutable_column_device_view::create(output_column->mutable_view(), stream);

Expand Down
16 changes: 16 additions & 0 deletions cpp/tests/ast/transform_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ TEST_F(TransformTest, BasicAddition)
CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, result->view(), verbosity);
}

TEST_F(TransformTest, BasicAdditionEmptyTable)
{
auto c_0 = column_wrapper<int32_t>{};
auto c_1 = column_wrapper<int32_t>{};
auto table = cudf::table_view{{c_0, c_1}};

auto col_ref_0 = cudf::ast::column_reference(0);
auto col_ref_1 = cudf::ast::column_reference(1);
auto expression = cudf::ast::operation(cudf::ast::ast_operator::ADD, col_ref_0, col_ref_1);

auto expected = column_wrapper<int32_t>{};
auto result = cudf::compute_column(table, expression);

CUDF_TEST_EXPECT_COLUMNS_EQUAL(expected, result->view(), verbosity);
}

TEST_F(TransformTest, BasicAdditionCast)
{
auto c_0 = column_wrapper<int64_t>{3, 20, 1, 50};
Expand Down
16 changes: 13 additions & 3 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9757,9 +9757,19 @@ def test_empty_numeric_only(data):
assert_eq(expected, actual)


@pytest.fixture
def df_eval():
N = 10
@pytest.fixture(params=[0, 10], ids=["empty", "10"])
def df_eval(request):
N = request.param
if N == 0:
value = np.zeros(0, dtype="int")
return cudf.DataFrame(
{
"a": value,
"b": value,
"c": value,
"d": value,
}
)
int_max = 10
rng = cupy.random.default_rng(0)
return cudf.DataFrame(
Expand Down

0 comments on commit dfacb95

Please sign in to comment.