Skip to content

Commit a8a3670

Browse files
authored
Move exception handler into pylibcudf from cudf (#16468)
PR to help prepare for the splitting out of pylibcudf. Authors: - Thomas Li (https://github.com/lithomas1) Approvers: - Bradley Dice (https://github.com/bdice) URL: #16468
1 parent 05745d0 commit a8a3670

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

docs/cudf/source/developer_guide/pylibcudf.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Some guidelines on what should be tested:
149149
- 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.
150150
- Nullable data should always be tested.
151151
- 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.
152-
- 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).
152+
- 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`.
153153

154154
Some guidelines on how best to use pytests.
155155
- 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.

python/cudf/cudf/_lib/exception_handler.pxd python/cudf/cudf/_lib/pylibcudf/exception_handler.pxd

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023, NVIDIA CORPORATION.
1+
# Copyright (c) 2023-2024, NVIDIA CORPORATION.
22

33

44
# See
@@ -24,7 +24,7 @@ cdef extern from *:
2424
* Since this function interoperates with Python's exception state, it
2525
* does not throw any C++ exceptions.
2626
*/
27-
void cudf_exception_handler()
27+
void libcudf_exception_handler()
2828
{
2929
// Catch a handful of different errors here and turn them into the
3030
// equivalent Python errors.
@@ -66,4 +66,4 @@ cdef extern from *:
6666
6767
} // anonymous namespace
6868
"""
69-
cdef void cudf_exception_handler()
69+
cdef void libcudf_exception_handler()

python/cudf/cudf/_lib/pylibcudf/libcudf/binaryop.pxd

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from libcpp cimport bool
55
from libcpp.memory cimport unique_ptr
66
from libcpp.string cimport string
77

8-
from cudf._lib.exception_handler cimport cudf_exception_handler
8+
from cudf._lib.pylibcudf.exception_handler cimport libcudf_exception_handler
99
from cudf._lib.pylibcudf.libcudf.column.column cimport column
1010
from cudf._lib.pylibcudf.libcudf.column.column_view cimport column_view
1111
from cudf._lib.pylibcudf.libcudf.scalar.scalar cimport scalar
@@ -55,33 +55,33 @@ cdef extern from "cudf/binaryop.hpp" namespace "cudf" nogil:
5555
const column_view& rhs,
5656
binary_operator op,
5757
data_type output_type
58-
) except +cudf_exception_handler
58+
) except +libcudf_exception_handler
5959

6060
cdef unique_ptr[column] binary_operation (
6161
const column_view& lhs,
6262
const scalar& rhs,
6363
binary_operator op,
6464
data_type output_type
65-
) except +cudf_exception_handler
65+
) except +libcudf_exception_handler
6666

6767
cdef unique_ptr[column] binary_operation (
6868
const column_view& lhs,
6969
const column_view& rhs,
7070
binary_operator op,
7171
data_type output_type
72-
) except +cudf_exception_handler
72+
) except +libcudf_exception_handler
7373

7474
cdef unique_ptr[column] binary_operation (
7575
const column_view& lhs,
7676
const column_view& rhs,
7777
const string& op,
7878
data_type output_type
79-
) except +cudf_exception_handler
79+
) except +libcudf_exception_handler
8080

8181
cdef extern from "cudf/binaryop.hpp" namespace "cudf::binops" nogil:
8282
cdef bool is_supported_operation(
8383
data_type output_type,
8484
data_type lhs_type,
8585
data_type rhs_type,
8686
binary_operator op
87-
) except +cudf_exception_handler
87+
) except +libcudf_exception_handler

python/cudf/cudf/_lib/pylibcudf/libcudf/copying.pxd

+22-22
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from libcpp.vector cimport vector
88

99
from rmm._lib.device_buffer cimport device_buffer
1010

11-
from cudf._lib.exception_handler cimport cudf_exception_handler
11+
from cudf._lib.pylibcudf.exception_handler cimport libcudf_exception_handler
1212
from cudf._lib.pylibcudf.libcudf.column.column cimport column
1313
from cudf._lib.pylibcudf.libcudf.column.column_view cimport (
1414
column_view,
@@ -30,25 +30,25 @@ cdef extern from "cudf/copying.hpp" namespace "cudf" nogil:
3030
const table_view& source_table,
3131
const column_view& gather_map,
3232
out_of_bounds_policy policy
33-
) except +cudf_exception_handler
33+
) except +libcudf_exception_handler
3434

3535
cdef unique_ptr[column] shift(
3636
const column_view& input,
3737
size_type offset,
3838
const scalar& fill_values
39-
) except +cudf_exception_handler
39+
) except +libcudf_exception_handler
4040

4141
cdef unique_ptr[table] scatter (
4242
const table_view& source_table,
4343
const column_view& scatter_map,
4444
const table_view& target_table,
45-
) except +cudf_exception_handler
45+
) except +libcudf_exception_handler
4646

4747
cdef unique_ptr[table] scatter (
4848
const vector[reference_wrapper[constscalar]]& source_scalars,
4949
const column_view& indices,
5050
const table_view& target,
51-
) except +cudf_exception_handler
51+
) except +libcudf_exception_handler
5252

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

5858
cdef unique_ptr[column] empty_like (
5959
const column_view& input_column
60-
) except +cudf_exception_handler
60+
) except +libcudf_exception_handler
6161

6262
cdef unique_ptr[column] allocate_like (
6363
const column_view& input_column,
6464
mask_allocation_policy policy
65-
) except +cudf_exception_handler
65+
) except +libcudf_exception_handler
6666

6767
cdef unique_ptr[column] allocate_like (
6868
const column_view& input_column,
6969
size_type size,
7070
mask_allocation_policy policy
71-
) except +cudf_exception_handler
71+
) except +libcudf_exception_handler
7272

7373
cdef unique_ptr[table] empty_like (
7474
const table_view& input_table
75-
) except +cudf_exception_handler
75+
) except +libcudf_exception_handler
7676

7777
cdef void copy_range_in_place (
7878
const column_view& input_column,
7979
mutable_column_view& target_column,
8080
size_type input_begin,
8181
size_type input_end,
8282
size_type target_begin
83-
) except +cudf_exception_handler
83+
) except +libcudf_exception_handler
8484

8585
cdef unique_ptr[column] copy_range (
8686
const column_view& input_column,
8787
const column_view& target_column,
8888
size_type input_begin,
8989
size_type input_end,
9090
size_type target_begin
91-
) except +cudf_exception_handler
91+
) except +libcudf_exception_handler
9292

9393
cdef vector[column_view] slice (
9494
const column_view& input_column,
9595
vector[size_type] indices
96-
) except +cudf_exception_handler
96+
) except +libcudf_exception_handler
9797

9898
cdef vector[table_view] slice (
9999
const table_view& input_table,
100100
vector[size_type] indices
101-
) except +cudf_exception_handler
101+
) except +libcudf_exception_handler
102102

103103
cdef vector[column_view] split (
104104
const column_view& input_column,
105105
vector[size_type] splits
106-
) except +cudf_exception_handler
106+
) except +libcudf_exception_handler
107107

108108
cdef vector[table_view] split (
109109
const table_view& input_table,
110110
vector[size_type] splits
111-
) except +cudf_exception_handler
111+
) except +libcudf_exception_handler
112112

113113
cdef unique_ptr[column] copy_if_else (
114114
const column_view& lhs,
115115
const column_view& rhs,
116116
const column_view& boolean_mask
117-
) except +cudf_exception_handler
117+
) except +libcudf_exception_handler
118118

119119
cdef unique_ptr[column] copy_if_else (
120120
const scalar& lhs,
121121
const column_view& rhs,
122122
const column_view& boolean_mask
123-
) except +cudf_exception_handler
123+
) except +libcudf_exception_handler
124124

125125
cdef unique_ptr[column] copy_if_else (
126126
const column_view& lhs,
127127
const scalar& rhs,
128128
const column_view boolean_mask
129-
) except +cudf_exception_handler
129+
) except +libcudf_exception_handler
130130

131131
cdef unique_ptr[column] copy_if_else (
132132
const scalar& lhs,
133133
const scalar& rhs,
134134
const column_view boolean_mask
135-
) except +cudf_exception_handler
135+
) except +libcudf_exception_handler
136136

137137
cdef unique_ptr[table] boolean_mask_scatter (
138138
const table_view& input,
139139
const table_view& target,
140140
const column_view& boolean_mask
141-
) except +cudf_exception_handler
141+
) except +libcudf_exception_handler
142142

143143
cdef unique_ptr[table] boolean_mask_scatter (
144144
const vector[reference_wrapper[constscalar]]& input,
145145
const table_view& target,
146146
const column_view& boolean_mask
147-
) except +cudf_exception_handler
147+
) except +libcudf_exception_handler
148148

149149
cdef unique_ptr[scalar] get_element (
150150
const column_view& input,
151151
size_type index
152-
) except +cudf_exception_handler
152+
) except +libcudf_exception_handler
153153

154154
cpdef enum class sample_with_replacement(bool):
155155
FALSE

python/cudf/cudf/_lib/pylibcudf/libcudf/lists/contains.pxd

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from libc.stdint cimport int32_t
44
from libcpp.memory cimport unique_ptr
55

6-
from cudf._lib.exception_handler cimport cudf_exception_handler
6+
from cudf._lib.pylibcudf.exception_handler cimport libcudf_exception_handler
77
from cudf._lib.pylibcudf.libcudf.column.column cimport column
88
from cudf._lib.pylibcudf.libcudf.column.column_view cimport column_view
99
from cudf._lib.pylibcudf.libcudf.lists.lists_column_view cimport (
@@ -21,25 +21,25 @@ cdef extern from "cudf/lists/contains.hpp" namespace "cudf::lists" nogil:
2121
cdef unique_ptr[column] contains(
2222
const lists_column_view& lists,
2323
const scalar& search_key,
24-
) except +cudf_exception_handler
24+
) except +libcudf_exception_handler
2525

2626
cdef unique_ptr[column] contains(
2727
const lists_column_view& lists,
2828
const column_view& search_keys,
29-
) except +cudf_exception_handler
29+
) except +libcudf_exception_handler
3030

3131
cdef unique_ptr[column] contains_nulls(
3232
const lists_column_view& lists,
33-
) except +cudf_exception_handler
33+
) except +libcudf_exception_handler
3434

3535
cdef unique_ptr[column] index_of(
3636
const lists_column_view& lists,
3737
const scalar& search_key,
3838
duplicate_find_option find_option,
39-
) except +cudf_exception_handler
39+
) except +libcudf_exception_handler
4040

4141
cdef unique_ptr[column] index_of(
4242
const lists_column_view& lists,
4343
const column_view& search_keys,
4444
duplicate_find_option find_option,
45-
) except +cudf_exception_handler
45+
) except +libcudf_exception_handler

0 commit comments

Comments
 (0)