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

Move exception handler into pylibcudf from cudf #16468

Merged
merged 4 commits into from
Aug 1, 2024
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
2 changes: 1 addition & 1 deletion docs/cudf/source/developer_guide/pylibcudf.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Some guidelines on what should be tested:
- Exception: In special cases where constructing suitable large tests is difficult in C++ (such as creating suitable input data for I/O testing), tests may be added to pylibcudf instead.
- Nullable data should always be tested.
- Expected exceptions should be tested. Tests should be written from the user's perspective in mind, and if the API is not currently throwing the appropriate exception it should be updated.
- Important note: If the exception should be produced by libcudf, the underlying libcudf API should be updated to throw the desired exception in C++. Such changes may require consultation with libcudf devs in nontrivial cases. [This issue](https://github.com/rapidsai/cudf/issues/12885) provides an overview and an indication of acceptable exception types that should cover most use cases. In rare cases a new C++ exception may need to be introduced in [`error.hpp`](https://github.com/rapidsai/cudf/blob/branch-24.04/cpp/include/cudf/utilities/error.hpp). If so, this exception will also need to be mapped to a suitable Python exception in [`exception_handler.pxd`](https://github.com/rapidsai/cudf/blob/branch-24.04/python/cudf/cudf/_lib/exception_handler.pxd).
- Important note: If the exception should be produced by libcudf, the underlying libcudf API should be updated to throw the desired exception in C++. Such changes may require consultation with libcudf devs in nontrivial cases. [This issue](https://github.com/rapidsai/cudf/issues/12885) provides an overview and an indication of acceptable exception types that should cover most use cases. In rare cases a new C++ exception may need to be introduced in [`error.hpp`](https://github.com/rapidsai/cudf/blob/branch-24.04/cpp/include/cudf/utilities/error.hpp). If so, this exception will also need to be mapped to a suitable Python exception in `exception_handler.pxd`.

Some guidelines on how best to use pytests.
- By default, fixtures producing device data containers should be of module scope and treated as immutable by tests. Allocating data on the GPU is expensive and slows tests. Almost all pylibcudf operations are out of place operations, so module-scoped fixtures should not typically be problematic to work with. Session-scoped fixtures would also work, but they are harder to reason about since they live in a different module, and if they need to change for any reason they could affect an arbitrarily large number of tests. Module scope is a good balance.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, NVIDIA CORPORATION.


# See
Expand All @@ -24,7 +24,7 @@ cdef extern from *:
* Since this function interoperates with Python's exception state, it
* does not throw any C++ exceptions.
*/
void cudf_exception_handler()
void libcudf_exception_handler()
{
// Catch a handful of different errors here and turn them into the
// equivalent Python errors.
Expand Down Expand Up @@ -66,4 +66,4 @@ cdef extern from *:

} // anonymous namespace
"""
cdef void cudf_exception_handler()
cdef void libcudf_exception_handler()
12 changes: 6 additions & 6 deletions python/cudf/cudf/_lib/pylibcudf/libcudf/binaryop.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from libcpp cimport bool
from libcpp.memory cimport unique_ptr
from libcpp.string cimport string

from cudf._lib.exception_handler cimport cudf_exception_handler
from cudf._lib.pylibcudf.exception_handler cimport libcudf_exception_handler
from cudf._lib.pylibcudf.libcudf.column.column cimport column
from cudf._lib.pylibcudf.libcudf.column.column_view cimport column_view
from cudf._lib.pylibcudf.libcudf.scalar.scalar cimport scalar
Expand Down Expand Up @@ -55,33 +55,33 @@ cdef extern from "cudf/binaryop.hpp" namespace "cudf" nogil:
const column_view& rhs,
binary_operator op,
data_type output_type
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] binary_operation (
const column_view& lhs,
const scalar& rhs,
binary_operator op,
data_type output_type
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] binary_operation (
const column_view& lhs,
const column_view& rhs,
binary_operator op,
data_type output_type
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] binary_operation (
const column_view& lhs,
const column_view& rhs,
const string& op,
data_type output_type
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef extern from "cudf/binaryop.hpp" namespace "cudf::binops" nogil:
cdef bool is_supported_operation(
data_type output_type,
data_type lhs_type,
data_type rhs_type,
binary_operator op
) except +cudf_exception_handler
) except +libcudf_exception_handler
44 changes: 22 additions & 22 deletions python/cudf/cudf/_lib/pylibcudf/libcudf/copying.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ from libcpp.vector cimport vector

from rmm._lib.device_buffer cimport device_buffer

from cudf._lib.exception_handler cimport cudf_exception_handler
from cudf._lib.pylibcudf.exception_handler cimport libcudf_exception_handler
from cudf._lib.pylibcudf.libcudf.column.column cimport column
from cudf._lib.pylibcudf.libcudf.column.column_view cimport (
column_view,
Expand All @@ -30,25 +30,25 @@ cdef extern from "cudf/copying.hpp" namespace "cudf" nogil:
const table_view& source_table,
const column_view& gather_map,
out_of_bounds_policy policy
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] shift(
const column_view& input,
size_type offset,
const scalar& fill_values
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[table] scatter (
const table_view& source_table,
const column_view& scatter_map,
const table_view& target_table,
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[table] scatter (
const vector[reference_wrapper[constscalar]]& source_scalars,
const column_view& indices,
const table_view& target,
) except +cudf_exception_handler
) except +libcudf_exception_handler

cpdef enum class mask_allocation_policy(int32_t):
NEVER
Expand All @@ -57,99 +57,99 @@ cdef extern from "cudf/copying.hpp" namespace "cudf" nogil:

cdef unique_ptr[column] empty_like (
const column_view& input_column
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] allocate_like (
const column_view& input_column,
mask_allocation_policy policy
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] allocate_like (
const column_view& input_column,
size_type size,
mask_allocation_policy policy
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[table] empty_like (
const table_view& input_table
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef void copy_range_in_place (
const column_view& input_column,
mutable_column_view& target_column,
size_type input_begin,
size_type input_end,
size_type target_begin
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] copy_range (
const column_view& input_column,
const column_view& target_column,
size_type input_begin,
size_type input_end,
size_type target_begin
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef vector[column_view] slice (
const column_view& input_column,
vector[size_type] indices
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef vector[table_view] slice (
const table_view& input_table,
vector[size_type] indices
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef vector[column_view] split (
const column_view& input_column,
vector[size_type] splits
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef vector[table_view] split (
const table_view& input_table,
vector[size_type] splits
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] copy_if_else (
const column_view& lhs,
const column_view& rhs,
const column_view& boolean_mask
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] copy_if_else (
const scalar& lhs,
const column_view& rhs,
const column_view& boolean_mask
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] copy_if_else (
const column_view& lhs,
const scalar& rhs,
const column_view boolean_mask
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] copy_if_else (
const scalar& lhs,
const scalar& rhs,
const column_view boolean_mask
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[table] boolean_mask_scatter (
const table_view& input,
const table_view& target,
const column_view& boolean_mask
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[table] boolean_mask_scatter (
const vector[reference_wrapper[constscalar]]& input,
const table_view& target,
const column_view& boolean_mask
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[scalar] get_element (
const column_view& input,
size_type index
) except +cudf_exception_handler
) except +libcudf_exception_handler

cpdef enum class sample_with_replacement(bool):
FALSE
Expand Down
12 changes: 6 additions & 6 deletions python/cudf/cudf/_lib/pylibcudf/libcudf/lists/contains.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from libc.stdint cimport int32_t
from libcpp.memory cimport unique_ptr

from cudf._lib.exception_handler cimport cudf_exception_handler
from cudf._lib.pylibcudf.exception_handler cimport libcudf_exception_handler
from cudf._lib.pylibcudf.libcudf.column.column cimport column
from cudf._lib.pylibcudf.libcudf.column.column_view cimport column_view
from cudf._lib.pylibcudf.libcudf.lists.lists_column_view cimport (
Expand All @@ -21,25 +21,25 @@ cdef extern from "cudf/lists/contains.hpp" namespace "cudf::lists" nogil:
cdef unique_ptr[column] contains(
const lists_column_view& lists,
const scalar& search_key,
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] contains(
const lists_column_view& lists,
const column_view& search_keys,
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] contains_nulls(
const lists_column_view& lists,
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] index_of(
const lists_column_view& lists,
const scalar& search_key,
duplicate_find_option find_option,
) except +cudf_exception_handler
) except +libcudf_exception_handler

cdef unique_ptr[column] index_of(
const lists_column_view& lists,
const column_view& search_keys,
duplicate_find_option find_option,
) except +cudf_exception_handler
) except +libcudf_exception_handler
Loading