diff --git a/cpp/src/strings/search/findall.cu b/cpp/src/strings/search/findall.cu index e6300ab63ff..0c1633dc3c9 100644 --- a/cpp/src/strings/search/findall.cu +++ b/cpp/src/strings/search/findall.cu @@ -134,8 +134,7 @@ struct find_re_fn { auto const d_str = d_strings.element(idx); auto const result = prog.find(thread_idx, d_str, d_str.begin()); - if (!result.has_value()) { return -1; } - return result.value().first; + return result.has_value() ? result.value().first : -1; } }; } // namespace @@ -153,10 +152,8 @@ std::unique_ptr find_re(strings_column_view const& input, mr); if (input.is_empty()) { return results; } - auto d_results = results->mutable_view().data(); - - auto d_prog = regex_device_builder::create_prog_device(prog, stream); - + auto d_results = results->mutable_view().data(); + auto d_prog = regex_device_builder::create_prog_device(prog, stream); auto const d_strings = column_device_view::create(input.parent(), stream); launch_transform_kernel(find_re_fn{*d_strings}, *d_prog, d_results, input.size(), stream); diff --git a/cpp/tests/strings/findall_tests.cpp b/cpp/tests/strings/findall_tests.cpp index 767ba05f158..ae423a81e7e 100644 --- a/cpp/tests/strings/findall_tests.cpp +++ b/cpp/tests/strings/findall_tests.cpp @@ -165,3 +165,16 @@ TEST_F(StringsFindallTests, FindTest) cudf::test::fixed_width_column_wrapper({0, 3, 3, -1, 1, 0, -1, 15}, valids); CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(results->view(), expected); } + +TEST_F(StringsFindallTests, EmptyTest) +{ + cudf::test::strings_column_wrapper input; + auto sv = cudf::strings_column_view(input); + + auto pattern = std::string("\\w+"); + + auto prog = cudf::strings::regex_program::create(pattern); + auto results = cudf::strings::find_re(sv, *prog); + auto expected = cudf::test::fixed_width_column_wrapper(); + CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(results->view(), expected); +}