From eb79b08071a441faf1a9e64e7ba9ded29d4d969d Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Fri, 28 Apr 2023 11:23:26 +0100 Subject: [PATCH 1/3] Allow zero-sized output in compute_column Closes #13236. --- cpp/src/transform/compute_column.cu | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cpp/src/transform/compute_column.cu b/cpp/src/transform/compute_column.cu index e11ff437c14..8fa5e75664f 100644 --- a/cpp/src/transform/compute_column.cu +++ b/cpp/src/transform/compute_column.cu @@ -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. @@ -97,6 +97,7 @@ std::unique_ptr 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); From 8e61e3278758d95c83eab0684d81c1df2893ce90 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Fri, 28 Apr 2023 11:30:38 +0100 Subject: [PATCH 2/3] Add test of AST addition on empty table --- cpp/tests/ast/transform_tests.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cpp/tests/ast/transform_tests.cpp b/cpp/tests/ast/transform_tests.cpp index 745fa44d45e..737224f2624 100644 --- a/cpp/tests/ast/transform_tests.cpp +++ b/cpp/tests/ast/transform_tests.cpp @@ -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{}; + auto c_1 = column_wrapper{}; + 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{}; + 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{3, 20, 1, 50}; From ea01fa174f820460398ca5c14c6dae851d815202 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Fri, 28 Apr 2023 11:38:29 +0100 Subject: [PATCH 3/3] Test df.eval on empty dataframes --- python/cudf/cudf/tests/test_dataframe.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/python/cudf/cudf/tests/test_dataframe.py b/python/cudf/cudf/tests/test_dataframe.py index e38d42f1c94..918a10ffd75 100644 --- a/python/cudf/cudf/tests/test_dataframe.py +++ b/python/cudf/cudf/tests/test_dataframe.py @@ -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(