diff --git a/cpp/include/cudf/contiguous_split.hpp b/cpp/include/cudf/contiguous_split.hpp index 9ea4fa1780b..1bbbf73bd5d 100644 --- a/cpp/include/cudf/contiguous_split.hpp +++ b/cpp/include/cudf/contiguous_split.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, NVIDIA CORPORATION. + * Copyright (c) 2023-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -106,9 +106,9 @@ struct packed_table { * @endcode * * - * @throws cudf::logic_error if `splits` has end index > size of `input`. - * @throws cudf::logic_error When the value in `splits` is not in the range [0, input.size()). - * @throws cudf::logic_error When the values in the `splits` are 'strictly decreasing'. + * @throws std::out_of_range if `splits` has end index > size of `input`. + * @throws std::out_of_range When the value in `splits` is not in the range [0, input.size()). + * @throws std::invalid_argument When the values in the `splits` are 'strictly decreasing'. * * @param input View of a table to split * @param splits A vector of indices where the view will be split diff --git a/cpp/include/cudf/copying.hpp b/cpp/include/cudf/copying.hpp index b3a8836b193..b2cde82fada 100644 --- a/cpp/include/cudf/copying.hpp +++ b/cpp/include/cudf/copying.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2023, NVIDIA CORPORATION. + * Copyright (c) 2018-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,7 +66,7 @@ enum class out_of_bounds_policy : bool { * For dictionary columns, the keys column component is copied and not trimmed * if the gather results in abandoned key elements. * - * @throws cudf::logic_error if gather_map contains null values. + * @throws std::invalid_argument if gather_map contains null values. * * @param source_table The input columns whose rows will be gathered * @param gather_map View into a non-nullable column of integral indices that maps the @@ -152,6 +152,13 @@ std::unique_ptr reverse( * A negative value `i` in the `scatter_map` is interpreted as `i+n`, where `n` * is the number of rows in the `target` table. * + * @throws std::invalid_argument if the number of columns in source does not match the number of + * columns in target + * @throws std::invalid_argument if the number of rows in source does not match the number of + * elements in scatter_map + * @throws cudf::data_type_error if the data types of the source and target columns do not match + * @throws std::invalid_argument if scatter_map contains null values + * * @param source The input columns containing values to be scattered into the * target columns * @param scatter_map A non-nullable column of integral indices that maps the @@ -191,6 +198,11 @@ std::unique_ptr scatter( * If any values in `scatter_map` are outside of the interval [-n, n) where `n` * is the number of rows in the `target` table, behavior is undefined. * + * @throws std::invalid_argument if the number of scalars does not match the number of columns in + * target + * @throws std::invalid_argument if indices contains null values + * @throws cudf::data_type_error if the data types of the scalars and target columns do not match + * * @param source The input scalars containing values to be scattered into the * target columns * @param indices A non-nullable column of integral indices that indicate @@ -302,15 +314,15 @@ std::unique_ptr
empty_like(table_view const& input_table); * If @p source and @p target refer to the same elements and the ranges overlap, * the behavior is undefined. * - * @throws cudf::logic_error if memory reallocation is required (e.g. for + * @throws cudf::data_type_error if memory reallocation is required (e.g. for * variable width types). - * @throws cudf::logic_error for invalid range (if + * @throws std::out_of_range for invalid range (if * @p source_begin > @p source_end, @p source_begin < 0, * @p source_begin >= @p source.size(), @p source_end > @p source.size(), * @p target_begin < 0, target_begin >= @p target.size(), or * @p target_begin + (@p source_end - @p source_begin) > @p target.size()). - * @throws cudf::logic_error if @p target and @p source have different types. - * @throws cudf::logic_error if @p source has null values and @p target is not + * @throws cudf::data_type_error if @p target and @p source have different types. + * @throws std::invalid_argument if @p source has null values and @p target is not * nullable. * * @param source The column to copy from @@ -341,12 +353,13 @@ void copy_range_in_place(column_view const& source, * If @p source and @p target refer to the same elements and the ranges overlap, * the behavior is undefined. * - * @throws cudf::logic_error for invalid range (if - * @p source_begin > @p source_end, @p source_begin < 0, - * @p source_begin >= @p source.size(), @p source_end > @p source.size(), - * @p target_begin < 0, target_begin >= @p target.size(), or - * @p target_begin + (@p source_end - @p source_begin) > @p target.size()). - * @throws cudf::logic_error if @p target and @p source have different types. + * A range is considered invalid if: + * - Either the begin or end indices are out of bounds for the corresponding column + * - Begin is greater than end for source or target + * - The size of the source range would overflow the target column starting at target_begin + * + * @throws std::out_of_range for any invalid range. + * @throws cudf::data_type_error if @p target and @p source have different types. * * @param source The column to copy from inside the range * @param target The column to copy from outside the range @@ -399,8 +412,8 @@ std::unique_ptr copy_range( * @param stream CUDA stream used for device memory operations and kernel launches * @param mr Device memory resource used to allocate the returned result's device memory * - * @throw cudf::logic_error if @p input dtype is neither fixed-width nor string type - * @throw cudf::logic_error if @p fill_value dtype does not match @p input dtype. + * @throw cudf::data_type_error if @p input dtype is neither fixed-width nor string type + * @throw cudf::data_type_error if @p fill_value dtype does not match @p input dtype. * * @return The shifted column */ @@ -432,9 +445,9 @@ std::unique_ptr shift( * output: {{12, 14}, {20, 22, 24, 26}, {14, 16}, {}} * @endcode * - * @throws cudf::logic_error if `indices` size is not even. - * @throws cudf::logic_error When the values in the pair are strictly decreasing. - * @throws cudf::logic_error When any of the values in the pair don't belong to + * @throws std::invalid_argument if `indices` size is not even. + * @throws std::invalid_argument When the values in the pair are strictly decreasing. + * @throws std::out_of_range When any of the values in the pair don't belong to * the range [0, input.size()). * * @param input View of column to slice @@ -476,9 +489,9 @@ std::vector slice(column_view const& input, * {{52, 54}, {60, 22, 24, 26}, {14, 16}, {}}] * @endcode * - * @throws cudf::logic_error if `indices` size is not even. - * @throws cudf::logic_error When the values in the pair are strictly decreasing. - * @throws cudf::logic_error When any of the values in the pair don't belong to + * @throws std::invalid_argument if `indices` size is not even. + * @throws std::invalid_argument When the values in the pair are strictly decreasing. + * @throws std::out_of_range When any of the values in the pair don't belong to * the range [0, input.size()). * * @param input View of table to slice @@ -521,9 +534,9 @@ std::vector slice(table_view const& input, * output: {{10, 12}, {14, 16, 18}, {20, 22, 24, 26}, {28}} * @endcode * - * @throws cudf::logic_error if `splits` has end index > size of `input`. - * @throws cudf::logic_error When the value in `splits` is not in the range [0, input.size()). - * @throws cudf::logic_error When the values in the `splits` are 'strictly decreasing'. + * @throws std::out_of_range if `splits` has end index > size of `input`. + * @throws std::out_of_range When the value in `splits` is not in the range [0, input.size()). + * @throws std::invalid_argument When the values in the `splits` are 'strictly decreasing'. * * @param input View of column to split * @param splits Indices where the view will be split @@ -567,9 +580,9 @@ std::vector split(column_view const& input, * {{50, 52}, {54, 56, 58}, {60, 62, 64, 66}, {68}}] * @endcode * - * @throws cudf::logic_error if `splits` has end index > size of `input`. - * @throws cudf::logic_error When the value in `splits` is not in the range [0, input.size()). - * @throws cudf::logic_error When the values in the `splits` are 'strictly decreasing'. + * @throws std::out_of_range if `splits` has end index > size of `input`. + * @throws std::out_of_range When the value in `splits` is not in the range [0, input.size()). + * @throws std::invalid_argument When the values in the `splits` are 'strictly decreasing'. * * @param input View of a table to split * @param splits Indices where the view will be split @@ -594,10 +607,10 @@ std::vector split(table_view const& input, * Selects each element i in the output column from either @p rhs or @p lhs using the following * rule: `output[i] = (boolean_mask.valid(i) and boolean_mask[i]) ? lhs[i] : rhs[i]` * - * @throws cudf::logic_error if lhs and rhs are not of the same type - * @throws cudf::logic_error if lhs and rhs are not of the same length - * @throws cudf::logic_error if boolean mask is not of type bool - * @throws cudf::logic_error if boolean mask is not of the same length as lhs and rhs + * @throws cudf::data_type_error if lhs and rhs are not of the same type + * @throws std::invalid_argument if lhs and rhs are not of the same length + * @throws cudf::data_type_error if boolean mask is not of type bool + * @throws std::invalid_argument if boolean mask is not of the same length as lhs and rhs * @param lhs left-hand column_view * @param rhs right-hand column_view * @param boolean_mask column of `type_id::BOOL8` representing "left (true) / right (false)" @@ -621,9 +634,9 @@ std::unique_ptr copy_if_else( * Selects each element i in the output column from either @p rhs or @p lhs using the following * rule: `output[i] = (boolean_mask.valid(i) and boolean_mask[i]) ? lhs : rhs[i]` * - * @throws cudf::logic_error if lhs and rhs are not of the same type - * @throws cudf::logic_error if boolean mask is not of type bool - * @throws cudf::logic_error if boolean mask is not of the same length as rhs + * @throws cudf::data_type_error if lhs and rhs are not of the same type + * @throws cudf::data_type_error if boolean mask is not of type bool + * @throws std::invalid_argument if boolean mask is not of the same length as lhs and rhs * @param lhs left-hand scalar * @param rhs right-hand column_view * @param boolean_mask column of `type_id::BOOL8` representing "left (true) / right (false)" @@ -647,9 +660,9 @@ std::unique_ptr copy_if_else( * Selects each element i in the output column from either @p rhs or @p lhs using the following * rule: `output[i] = (boolean_mask.valid(i) and boolean_mask[i]) ? lhs[i] : rhs` * - * @throws cudf::logic_error if lhs and rhs are not of the same type - * @throws cudf::logic_error if boolean mask is not of type bool - * @throws cudf::logic_error if boolean mask is not of the same length as lhs + * @throws cudf::data_type_error if lhs and rhs are not of the same type + * @throws cudf::data_type_error if boolean mask is not of type bool + * @throws std::invalid_argument if boolean mask is not of the same length as lhs and rhs * @param lhs left-hand column_view * @param rhs right-hand scalar * @param boolean_mask column of `type_id::BOOL8` representing "left (true) / right (false)" @@ -713,11 +726,11 @@ std::unique_ptr copy_if_else( * output: {{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}} * @endcode * - * @throw cudf::logic_error if input.num_columns() != target.num_columns() - * @throws cudf::logic_error if any `i`th input_column type != `i`th target_column type - * @throws cudf::logic_error if boolean_mask.type() != bool - * @throws cudf::logic_error if boolean_mask.size() != target.num_rows() - * @throws cudf::logic_error if number of `true` in `boolean_mask` > input.num_rows() + * @throws std::invalid_argument if input.num_columns() != target.num_columns() + * @throws cudf::data_type_error if any `i`th input_column type != `i`th target_column type + * @throws cudf::data_type_error if boolean_mask.type() != bool + * @throws std::invalid_argument if boolean_mask.size() != target.num_rows() + * @throws std::invalid_argument if number of `true` in `boolean_mask` > input.num_rows() * * @param input table_view (set of dense columns) to scatter * @param target table_view to modify with scattered values from `input` @@ -740,8 +753,8 @@ std::unique_ptr
boolean_mask_scatter( * * @ingroup copy_scatter * - * The `i`th scalar in `input` will be written to all columns of the output - * table at the location of the `i`th true value in `boolean_mask`. + * The `i`th scalar in `input` will be written to the ith column of the output + * table at the location of every true value in `boolean_mask`. * All other rows in the output will equal the same row in `target`. * * @code{.pseudo} @@ -753,10 +766,10 @@ std::unique_ptr
boolean_mask_scatter( * output: {{ 11, 2, 3, 4, 11, 11, 7, 11, 11, 10}} * @endcode * - * @throw cudf::logic_error if input.size() != target.num_columns() - * @throws cudf::logic_error if any `i`th input_scalar type != `i`th target_column type - * @throws cudf::logic_error if boolean_mask.type() != bool - * @throws cudf::logic_error if boolean_mask.size() != target.size() + * @throws std::invalid_argument if input.size() != target.num_columns() + * @throws cudf::data_type_error if any `i`th input_column type != `i`th target_column type + * @throws cudf::data_type_error if boolean_mask.type() != bool + * @throws std::invalid_argument if boolean_mask.size() != target.num_rows() * * @param input scalars to scatter * @param target table_view to modify with scattered values from `input` @@ -779,7 +792,7 @@ std::unique_ptr
boolean_mask_scatter( * @warning This function is expensive (invokes a kernel launch). So, it is not * recommended to be used in performance sensitive code or inside a loop. * - * @throws cudf::logic_error if `index` is not within the range `[0, input.size())` + * @throws std::out_of_range if `index` is not within the range `[0, input.size())` * * @param input Column view to get the element from * @param index Index into `input` to get the element at diff --git a/cpp/include/cudf/detail/null_mask.cuh b/cpp/include/cudf/detail/null_mask.cuh index 3b55a62cec0..db373f47a01 100644 --- a/cpp/include/cudf/detail/null_mask.cuh +++ b/cpp/include/cudf/detail/null_mask.cuh @@ -368,13 +368,16 @@ template size_type validate_segmented_indices(IndexIterator indices_begin, IndexIterator indices_end) { auto const num_indices = static_cast(std::distance(indices_begin, indices_end)); - CUDF_EXPECTS(num_indices % 2 == 0, "Array of indices needs to have an even number of elements."); + CUDF_EXPECTS(num_indices % 2 == 0, + "Array of indices needs to have an even number of elements.", + std::invalid_argument); size_type const num_segments = num_indices / 2; for (size_type i = 0; i < num_segments; i++) { auto begin = indices_begin[2 * i]; auto end = indices_begin[2 * i + 1]; - CUDF_EXPECTS(begin >= 0, "Starting index cannot be negative."); - CUDF_EXPECTS(end >= begin, "End index cannot be smaller than the starting index."); + CUDF_EXPECTS(begin >= 0, "Starting index cannot be negative.", std::out_of_range); + CUDF_EXPECTS( + end >= begin, "End index cannot be smaller than the starting index.", std::invalid_argument); } return num_segments; } diff --git a/cpp/src/copying/contiguous_split.cu b/cpp/src/copying/contiguous_split.cu index c28237587eb..23224d3225d 100644 --- a/cpp/src/copying/contiguous_split.cu +++ b/cpp/src/copying/contiguous_split.cu @@ -48,6 +48,7 @@ #include #include +#include namespace cudf { namespace { @@ -1729,13 +1730,15 @@ bool check_inputs(cudf::table_view const& input, std::vector const& s if (input.num_columns() == 0) { return true; } if (splits.size() > 0) { CUDF_EXPECTS(splits.back() <= input.column(0).size(), - "splits can't exceed size of input columns"); + "splits can't exceed size of input columns", + std::out_of_range); } size_type begin = 0; for (auto end : splits) { - CUDF_EXPECTS(begin >= 0, "Starting index cannot be negative."); - CUDF_EXPECTS(end >= begin, "End index cannot be smaller than the starting index."); - CUDF_EXPECTS(end <= input.column(0).size(), "Slice range out of bounds."); + CUDF_EXPECTS(begin >= 0, "Starting index cannot be negative.", std::out_of_range); + CUDF_EXPECTS( + end >= begin, "End index cannot be smaller than the starting index.", std::invalid_argument); + CUDF_EXPECTS(end <= input.column(0).size(), "Slice range out of bounds.", std::out_of_range); begin = end; } return input.column(0).size() == 0; diff --git a/cpp/src/copying/copy.cu b/cpp/src/copying/copy.cu index 6b7fae32d48..8299c211fad 100644 --- a/cpp/src/copying/copy.cu +++ b/cpp/src/copying/copy.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,8 @@ #include #include +#include + namespace cudf { namespace detail { namespace { @@ -319,7 +321,8 @@ std::unique_ptr copy_if_else(Left const& lhs, rmm::mr::device_memory_resource* mr) { CUDF_EXPECTS(boolean_mask.type() == data_type(type_id::BOOL8), - "Boolean mask column must be of type type_id::BOOL8"); + "Boolean mask column must be of type type_id::BOOL8", + cudf::data_type_error); if (boolean_mask.is_empty()) { return cudf::empty_like(lhs); } @@ -356,9 +359,11 @@ std::unique_ptr copy_if_else(column_view const& lhs, rmm::mr::device_memory_resource* mr) { CUDF_EXPECTS(boolean_mask.size() == lhs.size(), - "Boolean mask column must be the same size as lhs and rhs columns"); - CUDF_EXPECTS(lhs.size() == rhs.size(), "Both columns must be of the size"); - CUDF_EXPECTS(lhs.type() == rhs.type(), "Both inputs must be of the same type"); + "Boolean mask column must be the same size as lhs and rhs columns", + std::invalid_argument); + CUDF_EXPECTS(lhs.size() == rhs.size(), "Both columns must be of the size", std::invalid_argument); + CUDF_EXPECTS( + lhs.type() == rhs.type(), "Both inputs must be of the same type", cudf::data_type_error); return copy_if_else(lhs, rhs, lhs.has_nulls(), rhs.has_nulls(), boolean_mask, stream, mr); } @@ -370,11 +375,13 @@ std::unique_ptr copy_if_else(scalar const& lhs, rmm::mr::device_memory_resource* mr) { CUDF_EXPECTS(boolean_mask.size() == rhs.size(), - "Boolean mask column must be the same size as rhs column"); + "Boolean mask column must be the same size as rhs column", + std::invalid_argument); auto rhs_type = cudf::is_dictionary(rhs.type()) ? cudf::dictionary_column_view(rhs).keys_type() : rhs.type(); - CUDF_EXPECTS(lhs.type() == rhs_type, "Both inputs must be of the same type"); + CUDF_EXPECTS( + lhs.type() == rhs_type, "Both inputs must be of the same type", cudf::data_type_error); return copy_if_else(lhs, rhs, !lhs.is_valid(stream), rhs.has_nulls(), boolean_mask, stream, mr); } @@ -386,11 +393,13 @@ std::unique_ptr copy_if_else(column_view const& lhs, rmm::mr::device_memory_resource* mr) { CUDF_EXPECTS(boolean_mask.size() == lhs.size(), - "Boolean mask column must be the same size as lhs column"); + "Boolean mask column must be the same size as lhs column", + std::invalid_argument); auto lhs_type = cudf::is_dictionary(lhs.type()) ? cudf::dictionary_column_view(lhs).keys_type() : lhs.type(); - CUDF_EXPECTS(lhs_type == rhs.type(), "Both inputs must be of the same type"); + CUDF_EXPECTS( + lhs_type == rhs.type(), "Both inputs must be of the same type", cudf::data_type_error); return copy_if_else(lhs, rhs, lhs.has_nulls(), !rhs.is_valid(stream), boolean_mask, stream, mr); } @@ -401,7 +410,8 @@ std::unique_ptr copy_if_else(scalar const& lhs, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - CUDF_EXPECTS(lhs.type() == rhs.type(), "Both inputs must be of the same type"); + CUDF_EXPECTS( + lhs.type() == rhs.type(), "Both inputs must be of the same type", cudf::data_type_error); return copy_if_else( lhs, rhs, !lhs.is_valid(stream), !rhs.is_valid(stream), boolean_mask, stream, mr); } diff --git a/cpp/src/copying/copy_range.cu b/cpp/src/copying/copy_range.cu index 61d51f1d284..038646d8cf4 100644 --- a/cpp/src/copying/copy_range.cu +++ b/cpp/src/copying/copy_range.cu @@ -38,6 +38,7 @@ #include #include +#include namespace { template @@ -202,14 +203,17 @@ void copy_range_in_place(column_view const& source, rmm::cuda_stream_view stream) { CUDF_EXPECTS(cudf::is_fixed_width(target.type()), - "In-place copy_range does not support variable-sized types."); + "In-place copy_range does not support variable-sized types.", + cudf::data_type_error); CUDF_EXPECTS((source_begin >= 0) && (source_end <= source.size()) && (source_begin <= source_end) && (target_begin >= 0) && (target_begin <= target.size() - (source_end - source_begin)), - "Range is out of bounds."); - CUDF_EXPECTS(target.type() == source.type(), "Data type mismatch."); + "Range is out of bounds.", + std::out_of_range); + CUDF_EXPECTS(target.type() == source.type(), "Data type mismatch.", cudf::data_type_error); CUDF_EXPECTS(target.nullable() || not source.has_nulls(), - "target should be nullable if source has null values."); + "target should be nullable if source has null values.", + std::invalid_argument); if (source_end != source_begin) { // otherwise no-op cudf::type_dispatcher(target.type(), @@ -232,8 +236,9 @@ std::unique_ptr copy_range(column_view const& source, CUDF_EXPECTS((source_begin >= 0) && (source_end <= source.size()) && (source_begin <= source_end) && (target_begin >= 0) && (target_begin <= target.size() - (source_end - source_begin)), - "Range is out of bounds."); - CUDF_EXPECTS(target.type() == source.type(), "Data type mismatch."); + "Range is out of bounds.", + std::out_of_range); + CUDF_EXPECTS(target.type() == source.type(), "Data type mismatch.", cudf::data_type_error); return cudf::type_dispatcher( target.type(), diff --git a/cpp/src/copying/gather.cu b/cpp/src/copying/gather.cu index 921f84b6b50..78748e5a00b 100644 --- a/cpp/src/copying/gather.cu +++ b/cpp/src/copying/gather.cu @@ -29,6 +29,8 @@ #include #include +#include + namespace cudf { namespace detail { @@ -39,7 +41,7 @@ std::unique_ptr
gather(table_view const& source_table, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - CUDF_EXPECTS(not gather_map.has_nulls(), "gather_map contains nulls"); + CUDF_EXPECTS(not gather_map.has_nulls(), "gather_map contains nulls", std::invalid_argument); // create index type normalizing iterator for the gather_map auto map_begin = indexalator_factory::make_input_iterator(gather_map); diff --git a/cpp/src/copying/get_element.cu b/cpp/src/copying/get_element.cu index a3f9be0bc76..2e804415439 100644 --- a/cpp/src/copying/get_element.cu +++ b/cpp/src/copying/get_element.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,8 @@ #include +#include + namespace cudf { namespace detail { @@ -193,7 +195,7 @@ std::unique_ptr get_element(column_view const& input, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) { - CUDF_EXPECTS(index >= 0 and index < input.size(), "Index out of bounds"); + CUDF_EXPECTS(index >= 0 and index < input.size(), "Index out of bounds", std::out_of_range); return type_dispatcher(input.type(), get_element_functor{}, input, index, stream, mr); } diff --git a/cpp/src/copying/scatter.cu b/cpp/src/copying/scatter.cu index baa5d85d4d4..7931df4c9f0 100644 --- a/cpp/src/copying/scatter.cu +++ b/cpp/src/copying/scatter.cu @@ -44,6 +44,8 @@ #include #include +#include + namespace cudf { namespace detail { namespace { @@ -109,7 +111,9 @@ struct column_scalar_scatterer_impl { rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr) const { - CUDF_EXPECTS(source.get().type() == target.type(), "scalar and column types must match"); + CUDF_EXPECTS(source.get().type() == target.type(), + "scalar and column types must match", + cudf::data_type_error); // make a copy of data and null mask from source auto result = std::make_unique(target, stream, mr); @@ -296,17 +300,20 @@ std::unique_ptr
scatter(table_view const& source, rmm::mr::device_memory_resource* mr) { CUDF_EXPECTS(source.num_columns() == target.num_columns(), - "Number of columns in source and target not equal"); + "Number of columns in source and target not equal", + std::invalid_argument); CUDF_EXPECTS(scatter_map.size() <= source.num_rows(), - "Size of scatter map must be equal to or less than source rows"); + "Size of scatter map must be equal to or less than source rows", + std::invalid_argument); CUDF_EXPECTS(std::equal(source.begin(), source.end(), target.begin(), [](auto const& col1, auto const& col2) { return col1.type().id() == col2.type().id(); }), - "Column types do not match between source and target"); - CUDF_EXPECTS(not scatter_map.has_nulls(), "Scatter map contains nulls"); + "Column types do not match between source and target", + cudf::data_type_error); + CUDF_EXPECTS(not scatter_map.has_nulls(), "Scatter map contains nulls", std::invalid_argument); if (scatter_map.is_empty()) { return std::make_unique
(target, stream, mr); } @@ -340,8 +347,9 @@ std::unique_ptr
scatter(std::vector> rmm::mr::device_memory_resource* mr) { CUDF_EXPECTS(source.size() == static_cast(target.num_columns()), - "Number of columns in source and target not equal"); - CUDF_EXPECTS(not indices.has_nulls(), "indices contains nulls"); + "Number of scalars in source and number of columns in target not equal", + std::invalid_argument); + CUDF_EXPECTS(not indices.has_nulls(), "indices contains nulls", std::invalid_argument); if (indices.is_empty()) { return std::make_unique
(target, stream, mr); } @@ -425,10 +433,14 @@ std::unique_ptr
boolean_mask_scatter(table_view const& input, rmm::mr::device_memory_resource* mr) { CUDF_EXPECTS(input.num_columns() == target.num_columns(), - "Mismatch in number of input columns and target columns"); + "Mismatch in number of input columns and target columns", + std::invalid_argument); CUDF_EXPECTS(boolean_mask.size() == target.num_rows(), - "Boolean mask size and number of target rows mismatch"); - CUDF_EXPECTS(boolean_mask.type().id() == type_id::BOOL8, "Mask must be of Boolean type"); + "Boolean mask size and number of target rows mismatch", + std::invalid_argument); + CUDF_EXPECTS(boolean_mask.type().id() == type_id::BOOL8, + "Mask must be of Boolean type", + cudf::data_type_error); // Count valid pair of input and columns as per type at each column index i CUDF_EXPECTS( std::all_of(thrust::counting_iterator(0), @@ -436,7 +448,8 @@ std::unique_ptr
boolean_mask_scatter(table_view const& input, [&input, &target](auto index) { return ((input.column(index).type().id()) == (target.column(index).type().id())); }), - "Type mismatch in input column and target column"); + "Type mismatch in input column and target column", + cudf::data_type_error); if (target.num_rows() != 0) { std::vector> out_columns(target.num_columns()); @@ -463,10 +476,14 @@ std::unique_ptr
boolean_mask_scatter( rmm::mr::device_memory_resource* mr) { CUDF_EXPECTS(static_cast(input.size()) == target.num_columns(), - "Mismatch in number of scalars and target columns"); + "Mismatch in number of scalars and target columns", + std::invalid_argument); CUDF_EXPECTS(boolean_mask.size() == target.num_rows(), - "Boolean mask size and number of target rows mismatch"); - CUDF_EXPECTS(boolean_mask.type().id() == type_id::BOOL8, "Mask must be of Boolean type"); + "Boolean mask size and number of target rows mismatch", + std::invalid_argument); + CUDF_EXPECTS(boolean_mask.type().id() == type_id::BOOL8, + "Mask must be of Boolean type", + cudf::data_type_error); // Count valid pair of input and columns as per type at each column/scalar index i CUDF_EXPECTS( @@ -475,7 +492,8 @@ std::unique_ptr
boolean_mask_scatter( [&input, &target](auto index) { return (input[index].get().type().id() == target.column(index).type().id()); }), - "Type mismatch in input scalar and target column"); + "Type mismatch in input scalar and target column", + cudf::data_type_error); if (target.num_rows() != 0) { std::vector> out_columns(target.num_columns()); diff --git a/cpp/src/copying/shift.cu b/cpp/src/copying/shift.cu index 89d6551737b..8e013bb1212 100644 --- a/cpp/src/copying/shift.cu +++ b/cpp/src/copying/shift.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +38,7 @@ #include #include #include +#include namespace cudf { namespace { @@ -71,7 +72,7 @@ struct shift_functor { std::unique_ptr> operator()(Args&&...) { - CUDF_FAIL("shift only supports fixed-width or string types."); + CUDF_FAIL("shift only supports fixed-width or string types.", cudf::data_type_error); } template @@ -157,7 +158,8 @@ std::unique_ptr shift(column_view const& input, rmm::mr::device_memory_resource* mr) { CUDF_EXPECTS(input.type() == fill_value.type(), - "shift requires each fill value type to match the corresponding column type."); + "shift requires each fill value type to match the corresponding column type.", + cudf::data_type_error); if (input.is_empty()) { return empty_like(input); } diff --git a/cpp/src/copying/slice.cu b/cpp/src/copying/slice.cu index 7c524dde3c8..dc37addf4ee 100644 --- a/cpp/src/copying/slice.cu +++ b/cpp/src/copying/slice.cu @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ #include #include +#include namespace cudf { namespace detail { @@ -39,9 +40,9 @@ ColumnView slice(ColumnView const& input, size_type end, rmm::cuda_stream_view stream) { - CUDF_EXPECTS(begin >= 0, "Invalid beginning of range."); - CUDF_EXPECTS(end >= begin, "Invalid end of range."); - CUDF_EXPECTS(end <= input.size(), "Slice range out of bounds."); + CUDF_EXPECTS(begin >= 0, "Invalid beginning of range.", std::out_of_range); + CUDF_EXPECTS(end >= begin, "Invalid end of range.", std::invalid_argument); + CUDF_EXPECTS(end <= input.size(), "Slice range out of bounds.", std::out_of_range); std::vector children{}; children.reserve(input.num_children()); @@ -72,7 +73,7 @@ std::vector slice(column_view const& input, host_span indices, rmm::cuda_stream_view stream) { - CUDF_EXPECTS(indices.size() % 2 == 0, "indices size must be even"); + CUDF_EXPECTS(indices.size() % 2 == 0, "indices size must be even", std::invalid_argument); if (indices.empty()) return {}; @@ -88,9 +89,10 @@ std::vector slice(column_view const& input, auto op = [&](auto i) { auto begin = indices[2 * i]; auto end = indices[2 * i + 1]; - CUDF_EXPECTS(begin >= 0, "Starting index cannot be negative."); - CUDF_EXPECTS(end >= begin, "End index cannot be smaller than the starting index."); - CUDF_EXPECTS(end <= input.size(), "Slice range out of bounds."); + CUDF_EXPECTS(begin >= 0, "Starting index cannot be negative.", std::out_of_range); + CUDF_EXPECTS( + end >= begin, "End index cannot be smaller than the starting index.", std::invalid_argument); + CUDF_EXPECTS(end <= input.size(), "Slice range out of bounds.", std::out_of_range); return column_view{input.type(), end - begin, input.head(), @@ -107,7 +109,7 @@ std::vector slice(table_view const& input, host_span indices, rmm::cuda_stream_view stream) { - CUDF_EXPECTS(indices.size() % 2 == 0, "indices size must be even"); + CUDF_EXPECTS(indices.size() % 2 == 0, "indices size must be even", std::invalid_argument); if (indices.empty()) { return {}; } // 2d arrangement of column_views that represent the outgoing table_views sliced_table[i][j] diff --git a/cpp/src/copying/split.cpp b/cpp/src/copying/split.cpp index 1621bcdb36d..832a72ed5b0 100644 --- a/cpp/src/copying/split.cpp +++ b/cpp/src/copying/split.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include #include +#include namespace cudf { namespace detail { @@ -34,7 +35,8 @@ std::vector split(T const& input, rmm::cuda_stream_view stream) { if (splits.empty() or column_size == 0) { return std::vector{input}; } - CUDF_EXPECTS(splits.back() <= column_size, "splits can't exceed size of input columns"); + CUDF_EXPECTS( + splits.back() <= column_size, "splits can't exceed size of input columns", std::out_of_range); // If the size is not zero, the split will always start at `0` std::vector indices{0}; diff --git a/cpp/tests/bitmask/bitmask_tests.cpp b/cpp/tests/bitmask/bitmask_tests.cpp index 72ef88e4ed1..4bf648bed5a 100644 --- a/cpp/tests/bitmask/bitmask_tests.cpp +++ b/cpp/tests/bitmask/bitmask_tests.cpp @@ -33,6 +33,8 @@ #include #include +#include + struct BitmaskUtilitiesTest : public cudf::test::BaseFixture {}; TEST_F(BitmaskUtilitiesTest, StateNullCount) @@ -110,10 +112,10 @@ TEST_F(CountBitmaskTest, NegativeStart) std::vector indices = {0, 16, -1, 32}; EXPECT_THROW( cudf::detail::segmented_count_set_bits(mask.data(), indices, cudf::get_default_stream()), - cudf::logic_error); + std::out_of_range); EXPECT_THROW( cudf::detail::segmented_valid_count(mask.data(), indices, cudf::get_default_stream()), - cudf::logic_error); + std::out_of_range); } TEST_F(CountBitmaskTest, StartLargerThanStop) @@ -127,10 +129,10 @@ TEST_F(CountBitmaskTest, StartLargerThanStop) std::vector indices = {0, 16, 31, 30}; EXPECT_THROW( cudf::detail::segmented_count_set_bits(mask.data(), indices, cudf::get_default_stream()), - cudf::logic_error); + std::invalid_argument); EXPECT_THROW( cudf::detail::segmented_valid_count(mask.data(), indices, cudf::get_default_stream()), - cudf::logic_error); + std::invalid_argument); } TEST_F(CountBitmaskTest, EmptyRange) diff --git a/cpp/tests/copying/copy_range_tests.cpp b/cpp/tests/copying/copy_range_tests.cpp index 96fbdcb1eb7..bcc0ac29b3e 100644 --- a/cpp/tests/copying/copy_range_tests.cpp +++ b/cpp/tests/copying/copy_range_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,8 @@ #include #include +#include + auto all_valid = [](cudf::size_type row) { return true; }; auto even_valid = [](cudf::size_type row) { return (row % 2 == 0); }; @@ -378,7 +380,7 @@ TEST_F(CopyRangeErrorTestFixture, InvalidInplaceCall) cudf::mutable_column_view target_view{target}; // source has null values but target is not nullable. - EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 0, size, 0), cudf::logic_error); + EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 0, size, 0), std::invalid_argument); std::vector strings{"", "this", "is", "a", "column", "of", "strings"}; auto target_string = cudf::test::strings_column_wrapper(strings.begin(), strings.end()); @@ -386,7 +388,7 @@ TEST_F(CopyRangeErrorTestFixture, InvalidInplaceCall) cudf::mutable_column_view target_view_string{target_string}; EXPECT_THROW(cudf::copy_range_in_place(source_string, target_view_string, 0, size, 0), - cudf::logic_error); + cudf::data_type_error); } TEST_F(CopyRangeErrorTestFixture, InvalidRange) @@ -407,32 +409,32 @@ TEST_F(CopyRangeErrorTestFixture, InvalidRange) EXPECT_NO_THROW(auto p_ret = cudf::copy_range(source, target, 0, 0, 0)); // source_begin is negative - EXPECT_THROW(cudf::copy_range_in_place(source, target_view, -1, size, 0), cudf::logic_error); - EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, -1, size, 0), cudf::logic_error); + EXPECT_THROW(cudf::copy_range_in_place(source, target_view, -1, size, 0), std::out_of_range); + EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, -1, size, 0), std::out_of_range); // source_begin > source_end - EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 10, 5, 0), cudf::logic_error); - EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, 10, 5, 0), cudf::logic_error); + EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 10, 5, 0), std::out_of_range); + EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, 10, 5, 0), std::out_of_range); // source_begin >= source.size() - EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 101, 100, 0), cudf::logic_error); - EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, 101, 100, 0), cudf::logic_error); + EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 101, 100, 0), std::out_of_range); + EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, 101, 100, 0), std::out_of_range); // source_end > source.size() - EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 99, 101, 0), cudf::logic_error); - EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, 99, 101, 0), cudf::logic_error); + EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 99, 101, 0), std::out_of_range); + EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, 99, 101, 0), std::out_of_range); // target_begin < 0 - EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 50, 100, -5), cudf::logic_error); - EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, 50, 100, -5), cudf::logic_error); + EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 50, 100, -5), std::out_of_range); + EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, 50, 100, -5), std::out_of_range); // target_begin >= target.size() - EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 50, 100, 100), cudf::logic_error); - EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, 50, 100, 100), cudf::logic_error); + EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 50, 100, 100), std::out_of_range); + EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, 50, 100, 100), std::out_of_range); // target_begin + (source_end - source_begin) > target.size() - EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 50, 100, 80), cudf::logic_error); - EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, 50, 100, 80), cudf::logic_error); + EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 50, 100, 80), std::out_of_range); + EXPECT_THROW(auto p_ret = cudf::copy_range(source, target, 50, 100, 80), std::out_of_range); // Empty column target = cudf::test::fixed_width_column_wrapper{}; @@ -457,8 +459,8 @@ TEST_F(CopyRangeErrorTestFixture, DTypeMismatch) cudf::mutable_column_view target_view{target}; - EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 0, 100, 0), cudf::logic_error); - EXPECT_THROW(cudf::copy_range(source, target, 0, 100, 0), cudf::logic_error); + EXPECT_THROW(cudf::copy_range_in_place(source, target_view, 0, 100, 0), cudf::data_type_error); + EXPECT_THROW(cudf::copy_range(source, target, 0, 100, 0), cudf::data_type_error); auto dict_target = cudf::dictionary::encode(target); auto dict_source = cudf::dictionary::encode(source); @@ -516,5 +518,5 @@ TYPED_TEST(FixedPointTypesCopyRange, FixedPointScaleMismatch) auto const source = fp_wrapper{{110, 220, 330, 440, 550, 660}, scale_type{-2}}; auto const target = fp_wrapper{{0, 0, 0, 0, 0, 0}, scale_type{-3}}; - EXPECT_THROW(cudf::copy_range(source, target, 1, 4, 1), cudf::logic_error); + EXPECT_THROW(cudf::copy_range(source, target, 1, 4, 1), cudf::data_type_error); } diff --git a/cpp/tests/copying/copy_tests.cpp b/cpp/tests/copying/copy_tests.cpp index 737937367d5..138e1935363 100644 --- a/cpp/tests/copying/copy_tests.cpp +++ b/cpp/tests/copying/copy_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,8 @@ #include #include +#include + template struct CopyTest : public cudf::test::BaseFixture {}; @@ -215,7 +217,7 @@ TYPED_TEST(CopyTest, CopyIfElseBadInputLength) wrapper lhs_w({5, 5, 5, 5}); wrapper rhs_w({6, 6, 6, 6}); - EXPECT_THROW(cudf::copy_if_else(lhs_w, rhs_w, mask_w), cudf::logic_error); + EXPECT_THROW(cudf::copy_if_else(lhs_w, rhs_w, mask_w), std::invalid_argument); } // column length mismatch @@ -225,7 +227,7 @@ TYPED_TEST(CopyTest, CopyIfElseBadInputLength) wrapper lhs_w({5, 5, 5}); wrapper rhs_w({6, 6, 6, 6}); - EXPECT_THROW(cudf::copy_if_else(lhs_w, rhs_w, mask_w), cudf::logic_error); + EXPECT_THROW(cudf::copy_if_else(lhs_w, rhs_w, mask_w), std::invalid_argument); } } @@ -465,7 +467,7 @@ TEST_F(CopyTestUntyped, CopyIfElseTypeMismatch) wrapper lhs_w{5, 5, 5, 5}; wrapper rhs_w{6, 6, 6, 6}; - EXPECT_THROW(cudf::copy_if_else(lhs_w, rhs_w, mask_w), cudf::logic_error); + EXPECT_THROW(cudf::copy_if_else(lhs_w, rhs_w, mask_w), cudf::data_type_error); } struct StringsCopyIfElseTest : public cudf::test::BaseFixture {}; @@ -634,7 +636,7 @@ TYPED_TEST(FixedPointTypes, FixedPointScaleMismatch) auto const a = fp_wrapper{{110, 220, 330, 440, 550, 660}, scale_type{-2}}; auto const b = fp_wrapper{{0, 0, 0, 0, 0, 0}, scale_type{-1}}; - EXPECT_THROW(cudf::copy_if_else(a, b, mask), cudf::logic_error); + EXPECT_THROW(cudf::copy_if_else(a, b, mask), cudf::data_type_error); } struct DictionaryCopyIfElseTest : public cudf::test::BaseFixture {}; @@ -713,7 +715,7 @@ TEST_F(DictionaryCopyIfElseTest, TypeMismatch) EXPECT_THROW(cudf::copy_if_else(input1, input2, mask), cudf::logic_error); cudf::string_scalar input3{"1"}; - EXPECT_THROW(cudf::copy_if_else(input1, input3, mask), cudf::logic_error); - EXPECT_THROW(cudf::copy_if_else(input3, input2, mask), cudf::logic_error); - EXPECT_THROW(cudf::copy_if_else(input2, input3, mask), cudf::logic_error); + EXPECT_THROW(cudf::copy_if_else(input1, input3, mask), cudf::data_type_error); + EXPECT_THROW(cudf::copy_if_else(input3, input2, mask), cudf::data_type_error); + EXPECT_THROW(cudf::copy_if_else(input2, input3, mask), cudf::data_type_error); } diff --git a/cpp/tests/copying/get_value_tests.cpp b/cpp/tests/copying/get_value_tests.cpp index d58aeb2ddfc..2be3c26af1d 100644 --- a/cpp/tests/copying/get_value_tests.cpp +++ b/cpp/tests/copying/get_value_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2023, NVIDIA CORPORATION. + * Copyright (c) 2020-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,8 @@ #include +#include + using namespace cudf::test::iterators; template @@ -77,8 +79,8 @@ TYPED_TEST(FixedWidthGetValueTest, IndexOutOfBounds) cudf::test::fixed_width_column_wrapper col({9, 8, 7, 6}, {0, 1, 0, 1}); // Test for out of bounds indexes in both directions. - EXPECT_THROW(cudf::get_element(col, -1), cudf::logic_error); - EXPECT_THROW(cudf::get_element(col, 4), cudf::logic_error); + EXPECT_THROW(cudf::get_element(col, -1), std::out_of_range); + EXPECT_THROW(cudf::get_element(col, 4), std::out_of_range); } struct StringGetValueTest : public cudf::test::BaseFixture {}; diff --git a/cpp/tests/copying/scatter_tests.cpp b/cpp/tests/copying/scatter_tests.cpp index 8194a74c10a..16cbeb7e657 100644 --- a/cpp/tests/copying/scatter_tests.cpp +++ b/cpp/tests/copying/scatter_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,8 @@ #include #include +#include + class ScatterUntypedTests : public cudf::test::BaseFixture {}; // Throw logic error if scatter map is longer than source @@ -37,7 +39,7 @@ TEST_F(ScatterUntypedTests, ScatterMapTooLong) auto const source_table = cudf::table_view({source, source}); auto const target_table = cudf::table_view({target, target}); - EXPECT_THROW(cudf::scatter(source_table, scatter_map, target_table), cudf::logic_error); + EXPECT_THROW(cudf::scatter(source_table, scatter_map, target_table), std::invalid_argument); } // Throw logic error if scatter map has nulls @@ -50,7 +52,7 @@ TEST_F(ScatterUntypedTests, ScatterMapNulls) auto const source_table = cudf::table_view({source, source}); auto const target_table = cudf::table_view({target, target}); - EXPECT_THROW(cudf::scatter(source_table, scatter_map, target_table), cudf::logic_error); + EXPECT_THROW(cudf::scatter(source_table, scatter_map, target_table), std::invalid_argument); } // Throw logic error if scatter map has nulls @@ -65,7 +67,7 @@ TEST_F(ScatterUntypedTests, ScatterScalarMapNulls) auto const target_table = cudf::table_view({target}); - EXPECT_THROW(cudf::scatter(source_vector, scatter_map, target_table), cudf::logic_error); + EXPECT_THROW(cudf::scatter(source_vector, scatter_map, target_table), std::invalid_argument); } // Throw logic error if source and target have different number of columns @@ -78,7 +80,7 @@ TEST_F(ScatterUntypedTests, ScatterColumnNumberMismatch) auto const source_table = cudf::table_view({source}); auto const target_table = cudf::table_view({target, target}); - EXPECT_THROW(cudf::scatter(source_table, scatter_map, target_table), cudf::logic_error); + EXPECT_THROW(cudf::scatter(source_table, scatter_map, target_table), std::invalid_argument); } // Throw logic error if number of scalars doesn't match number of columns @@ -93,7 +95,7 @@ TEST_F(ScatterUntypedTests, ScatterScalarColumnNumberMismatch) auto const target_table = cudf::table_view({target, target}); - EXPECT_THROW(cudf::scatter(source_vector, scatter_map, target_table), cudf::logic_error); + EXPECT_THROW(cudf::scatter(source_vector, scatter_map, target_table), std::invalid_argument); } // Throw logic error if source and target have different data types @@ -106,7 +108,7 @@ TEST_F(ScatterUntypedTests, ScatterDataTypeMismatch) auto const source_table = cudf::table_view({source}); auto const target_table = cudf::table_view({target}); - EXPECT_THROW(cudf::scatter(source_table, scatter_map, target_table), cudf::logic_error); + EXPECT_THROW(cudf::scatter(source_table, scatter_map, target_table), cudf::data_type_error); } // Throw logic error if source and target have different data types @@ -121,7 +123,7 @@ TEST_F(ScatterUntypedTests, ScatterScalarDataTypeMismatch) auto const target_table = cudf::table_view({target}); - EXPECT_THROW(cudf::scatter(source_vector, scatter_map, target_table), cudf::logic_error); + EXPECT_THROW(cudf::scatter(source_vector, scatter_map, target_table), cudf::data_type_error); } template @@ -589,7 +591,7 @@ TEST_F(BooleanMaskScatterFails, SourceAndTargetTypeMismatch) auto source_table = cudf::table_view({source}); auto target_table = cudf::table_view({target}); - EXPECT_THROW(cudf::boolean_mask_scatter(source_table, target_table, mask), cudf::logic_error); + EXPECT_THROW(cudf::boolean_mask_scatter(source_table, target_table, mask), cudf::data_type_error); } TEST_F(BooleanMaskScatterFails, BooleanMaskTypeMismatch) @@ -601,7 +603,7 @@ TEST_F(BooleanMaskScatterFails, BooleanMaskTypeMismatch) auto source_table = cudf::table_view({source}); auto target_table = cudf::table_view({target}); - EXPECT_THROW(cudf::boolean_mask_scatter(source_table, target_table, mask), cudf::logic_error); + EXPECT_THROW(cudf::boolean_mask_scatter(source_table, target_table, mask), cudf::data_type_error); } TEST_F(BooleanMaskScatterFails, BooleanMaskTargetSizeMismatch) @@ -613,7 +615,7 @@ TEST_F(BooleanMaskScatterFails, BooleanMaskTargetSizeMismatch) auto source_table = cudf::table_view({source}); auto target_table = cudf::table_view({target}); - EXPECT_THROW(cudf::boolean_mask_scatter(source_table, target_table, mask), cudf::logic_error); + EXPECT_THROW(cudf::boolean_mask_scatter(source_table, target_table, mask), std::invalid_argument); } TEST_F(BooleanMaskScatterFails, NumberOfColumnMismatch) @@ -625,7 +627,7 @@ TEST_F(BooleanMaskScatterFails, NumberOfColumnMismatch) auto source_table = cudf::table_view({source, source}); auto target_table = cudf::table_view({target}); - EXPECT_THROW(cudf::boolean_mask_scatter(source_table, target_table, mask), cudf::logic_error); + EXPECT_THROW(cudf::boolean_mask_scatter(source_table, target_table, mask), std::invalid_argument); } TEST_F(BooleanMaskScatterFails, MoreTruesInMaskThanSourceSize) @@ -637,7 +639,7 @@ TEST_F(BooleanMaskScatterFails, MoreTruesInMaskThanSourceSize) auto source_table = cudf::table_view({source, source}); auto target_table = cudf::table_view({target}); - EXPECT_THROW(cudf::boolean_mask_scatter(source_table, target_table, mask), cudf::logic_error); + EXPECT_THROW(cudf::boolean_mask_scatter(source_table, target_table, mask), std::invalid_argument); } template @@ -768,7 +770,7 @@ TEST_F(BooleanMaskScatterScalarFails, SourceAndTargetTypeMismatch) {true, false, false, false, true, true, false, true, true, false}); auto target_table = cudf::table_view({target}); - EXPECT_THROW(cudf::boolean_mask_scatter(scalar_vect, target_table, mask), cudf::logic_error); + EXPECT_THROW(cudf::boolean_mask_scatter(scalar_vect, target_table, mask), cudf::data_type_error); } TEST_F(BooleanMaskScatterScalarFails, BooleanMaskTypeMismatch) @@ -782,7 +784,7 @@ TEST_F(BooleanMaskScatterScalarFails, BooleanMaskTypeMismatch) {true, false, false, false, true, true, false, true, true, false}); auto target_table = cudf::table_view({target}); - EXPECT_THROW(cudf::boolean_mask_scatter(scalar_vect, target_table, mask), cudf::logic_error); + EXPECT_THROW(cudf::boolean_mask_scatter(scalar_vect, target_table, mask), cudf::data_type_error); } TEST_F(BooleanMaskScatterScalarFails, BooleanMaskTargetSizeMismatch) @@ -796,7 +798,7 @@ TEST_F(BooleanMaskScatterScalarFails, BooleanMaskTargetSizeMismatch) {true, false, false, false, true, true, false, true, true}); auto target_table = cudf::table_view({target}); - EXPECT_THROW(cudf::boolean_mask_scatter(scalar_vect, target_table, mask), cudf::logic_error); + EXPECT_THROW(cudf::boolean_mask_scatter(scalar_vect, target_table, mask), std::invalid_argument); } TEST_F(BooleanMaskScatterScalarFails, NumberOfColumnAndScalarMismatch) @@ -811,7 +813,7 @@ TEST_F(BooleanMaskScatterScalarFails, NumberOfColumnAndScalarMismatch) {true, false, false, false, true, true, false, true, true}); auto target_table = cudf::table_view({target}); - EXPECT_THROW(cudf::boolean_mask_scatter(scalar_vect, target_table, mask), cudf::logic_error); + EXPECT_THROW(cudf::boolean_mask_scatter(scalar_vect, target_table, mask), std::invalid_argument); } template diff --git a/cpp/tests/copying/shift_tests.cpp b/cpp/tests/copying/shift_tests.cpp index 17e56ea8ed8..f904696593c 100644 --- a/cpp/tests/copying/shift_tests.cpp +++ b/cpp/tests/copying/shift_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ #include #include +#include using TestTypes = cudf::test::Types; @@ -192,7 +193,7 @@ TYPED_TEST(ShiftTestsTyped, MismatchFillValueDtypes) auto fill = cudf::string_scalar(""); - EXPECT_THROW(cudf::shift(input, 5, fill), cudf::logic_error); + EXPECT_THROW(cudf::shift(input, 5, fill), cudf::data_type_error); } struct ShiftTests : public cudf::test::BaseFixture {}; diff --git a/cpp/tests/copying/slice_tests.cpp b/cpp/tests/copying/slice_tests.cpp index 29ff3e1cf9b..fffc51eef2c 100644 --- a/cpp/tests/copying/slice_tests.cpp +++ b/cpp/tests/copying/slice_tests.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -302,7 +303,7 @@ TEST_F(SliceCornerCases, InvalidSetOfIndices) create_fixed_columns(start, size, valids); std::vector indices{11, 12}; - EXPECT_THROW(cudf::slice(col, indices), cudf::logic_error); + EXPECT_THROW(cudf::slice(col, indices), std::out_of_range); } TEST_F(SliceCornerCases, ImproperRange) @@ -316,7 +317,7 @@ TEST_F(SliceCornerCases, ImproperRange) create_fixed_columns(start, size, valids); std::vector indices{5, 4}; - EXPECT_THROW(cudf::slice(col, indices), cudf::logic_error); + EXPECT_THROW(cudf::slice(col, indices), std::invalid_argument); } TEST_F(SliceCornerCases, NegativeOffset) @@ -330,7 +331,7 @@ TEST_F(SliceCornerCases, NegativeOffset) create_fixed_columns(start, size, valids); std::vector indices{-1, 4}; - EXPECT_THROW(cudf::slice(col, indices), cudf::logic_error); + EXPECT_THROW(cudf::slice(col, indices), std::out_of_range); } template @@ -437,7 +438,7 @@ TEST_F(SliceTableCornerCases, InvalidSetOfIndices) std::vector indices{11, 12}; - EXPECT_THROW(cudf::slice(src_table, indices), cudf::logic_error); + EXPECT_THROW(cudf::slice(src_table, indices), std::out_of_range); } TEST_F(SliceTableCornerCases, ImproperRange) @@ -452,7 +453,7 @@ TEST_F(SliceTableCornerCases, ImproperRange) std::vector indices{5, 4}; - EXPECT_THROW(cudf::slice(src_table, indices), cudf::logic_error); + EXPECT_THROW(cudf::slice(src_table, indices), std::invalid_argument); } TEST_F(SliceTableCornerCases, NegativeOffset) @@ -467,7 +468,7 @@ TEST_F(SliceTableCornerCases, NegativeOffset) std::vector indices{-1, 4}; - EXPECT_THROW(cudf::slice(src_table, indices), cudf::logic_error); + EXPECT_THROW(cudf::slice(src_table, indices), std::out_of_range); } TEST_F(SliceTableCornerCases, MiscOffset) diff --git a/cpp/tests/copying/split_tests.cpp b/cpp/tests/copying/split_tests.cpp index 7c3beabaedf..077092ca036 100644 --- a/cpp/tests/copying/split_tests.cpp +++ b/cpp/tests/copying/split_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2023, NVIDIA CORPORATION. + * Copyright (c) 2019-2024, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -368,7 +369,7 @@ TEST_F(SplitCornerCases, InvalidSetOfIndices) create_fixed_columns(start, size, valids); std::vector splits{11, 12}; - EXPECT_THROW(cudf::split(col, splits), cudf::logic_error); + EXPECT_THROW(cudf::split(col, splits), std::out_of_range); } TEST_F(SplitCornerCases, ImproperRange) @@ -382,7 +383,7 @@ TEST_F(SplitCornerCases, ImproperRange) create_fixed_columns(start, size, valids); std::vector splits{5, 4}; - EXPECT_THROW(cudf::split(col, splits), cudf::logic_error); + EXPECT_THROW(cudf::split(col, splits), std::invalid_argument); } TEST_F(SplitCornerCases, NegativeValue) @@ -396,7 +397,7 @@ TEST_F(SplitCornerCases, NegativeValue) create_fixed_columns(start, size, valids); std::vector splits{-1, 4}; - EXPECT_THROW(cudf::split(col, splits), cudf::logic_error); + EXPECT_THROW(cudf::split(col, splits), std::invalid_argument); } // common functions for testing split/contiguous_split @@ -491,7 +492,7 @@ void split_invalid_indices(SplitFunc Split) std::vector splits{11, 12}; - EXPECT_THROW(Split(src_table, splits), cudf::logic_error); + EXPECT_THROW(Split(src_table, splits), std::out_of_range); } template @@ -507,7 +508,7 @@ void split_improper_range(SplitFunc Split) std::vector splits{5, 4}; - EXPECT_THROW(Split(src_table, splits), cudf::logic_error); + EXPECT_THROW(Split(src_table, splits), std::invalid_argument); } template @@ -523,7 +524,7 @@ void split_negative_value(SplitFunc Split) std::vector splits{-1, 4}; - EXPECT_THROW(Split(src_table, splits), cudf::logic_error); + EXPECT_THROW(Split(src_table, splits), std::invalid_argument); } template @@ -2296,7 +2297,7 @@ TEST_F(ContiguousSplitTableCornerCases, SplitEmpty) } { - EXPECT_THROW(cudf::contiguous_split(sliced[0], {1}), cudf::logic_error); + EXPECT_THROW(cudf::contiguous_split(sliced[0], {1}), std::out_of_range); } }