Skip to content

Commit 04f385a

Browse files
authored
Merge pull request #1559 from kkraus14/fea-ext-cython-exceptions
[REVIEW] Catch C++ exceptions from Cython
2 parents 4e63437 + 23b1168 commit 04f385a

File tree

2 files changed

+36
-37
lines changed

2 files changed

+36
-37
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
- PR #1520 Renamed `src/dataframe` to `src/table` and moved `table.hpp`. Made `types.hpp` to be type declarations only.
6565
- PR #1521 Added `row_bitmask` to compute bitmask for rows of a table. Merged `valids_ops.cu` and `bitmask_ops.cu`
6666
- PR #1553 Overload `hash_row` to avoid using intial hash values. Updated `gdf_hash` to select between overloads
67+
- PR #1559 Add `except +` to all Cython function definitions to catch C++ exceptions properly
6768

6869

6970
## Bug Fixes

python/cudf/bindings/cudf_cpp.pxd

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ cdef gdf_dtype get_dtype(dtype)
2121
cdef get_scalar_value(gdf_scalar scalar)
2222

2323
cdef gdf_column* column_view_from_column(col)
24-
cdef gdf_column* column_view_from_NDArrays(size, data, mask,
25-
dtype, null_count)
24+
cdef gdf_column* column_view_from_NDArrays(size, data, mask, dtype, null_count)
2625
cdef gdf_column_to_column_mem(gdf_column* input_col)
2726
cdef update_nvstrings_col(col, uintptr_t category_ptr)
2827

@@ -189,49 +188,48 @@ cdef extern from "cudf.h" nogil:
189188
gdf_dtype dtype
190189
bool is_valid
191190

191+
cdef gdf_size_type gdf_column_sizeof() except +
192192

193-
cdef gdf_size_type gdf_column_sizeof()
194-
195-
gdf_error gdf_column_view(gdf_column *column, void *data, gdf_valid_type *valid,
196-
gdf_size_type size, gdf_dtype dtype)
193+
cdef gdf_error gdf_column_view(gdf_column *column, void *data, gdf_valid_type *valid,
194+
gdf_size_type size, gdf_dtype dtype) except +
197195

198196
cdef gdf_error gdf_column_view_augmented(gdf_column *column,
199197
void *data,
200198
gdf_valid_type *valid,
201199
gdf_size_type size,
202200
gdf_dtype dtype,
203201
gdf_size_type null_count,
204-
gdf_dtype_extra_info extra_info)
202+
gdf_dtype_extra_info extra_info) except +
205203

206-
cdef gdf_error gdf_column_free(gdf_column *column)
204+
cdef gdf_error gdf_column_free(gdf_column *column) except +
207205

208206
cdef gdf_error gdf_context_view(gdf_context *context,
209207
int flag_sorted,
210208
gdf_method flag_method,
211209
int flag_distinct,
212210
int flag_sort_result,
213-
int flag_sort_inplace)
211+
int flag_sort_inplace) except +
214212

215-
cdef const char * gdf_error_get_name(gdf_error errcode)
213+
cdef const char * gdf_error_get_name(gdf_error errcode) except +
216214

217-
cdef int gdf_cuda_last_error()
218-
cdef const char * gdf_cuda_error_string(int cuda_error)
219-
cdef const char * gdf_cuda_error_name(int cuda_error)
215+
cdef int gdf_cuda_last_error() except +
216+
cdef const char * gdf_cuda_error_string(int cuda_error) except +
217+
cdef const char * gdf_cuda_error_name(int cuda_error) except +
220218

221-
cdef gdf_ipc_parser_type* gdf_ipc_parser_open(const uint8_t *schema, size_t length)
219+
cdef gdf_ipc_parser_type* gdf_ipc_parser_open(const uint8_t *schema, size_t length) except +
222220
cdef void gdf_ipc_parser_open_recordbatches(gdf_ipc_parser_type *handle,
223221
const uint8_t *recordbatches,
224-
size_t length)
222+
size_t length) except +
225223

226-
cdef void gdf_ipc_parser_close(gdf_ipc_parser_type *handle)
227-
cdef int gdf_ipc_parser_failed(gdf_ipc_parser_type *handle)
228-
cdef const char* gdf_ipc_parser_to_json(gdf_ipc_parser_type *handle)
229-
cdef const char* gdf_ipc_parser_get_error(gdf_ipc_parser_type *handle)
230-
cdef const void* gdf_ipc_parser_get_data(gdf_ipc_parser_type *handle)
231-
cdef int64_t gdf_ipc_parser_get_data_offset(gdf_ipc_parser_type *handle)
224+
cdef void gdf_ipc_parser_close(gdf_ipc_parser_type *handle) except +
225+
cdef int gdf_ipc_parser_failed(gdf_ipc_parser_type *handle) except +
226+
cdef const char* gdf_ipc_parser_to_json(gdf_ipc_parser_type *handle) except +
227+
cdef const char* gdf_ipc_parser_get_error(gdf_ipc_parser_type *handle) except +
228+
cdef const void* gdf_ipc_parser_get_data(gdf_ipc_parser_type *handle) except +
229+
cdef int64_t gdf_ipc_parser_get_data_offset(gdf_ipc_parser_type *handle) except +
232230

233-
cdef const char *gdf_ipc_parser_get_schema_json(gdf_ipc_parser_type *handle)
234-
cdef const char *gdf_ipc_parser_get_layout_json(gdf_ipc_parser_type *handle)
231+
cdef const char *gdf_ipc_parser_get_schema_json(gdf_ipc_parser_type *handle) except +
232+
cdef const char *gdf_ipc_parser_get_layout_json(gdf_ipc_parser_type *handle) except +
235233

236234
cdef gdf_error gdf_inner_join(
237235
gdf_column **left_cols,
@@ -275,15 +273,15 @@ cdef extern from "cudf.h" nogil:
275273
gdf_column * right_indices,
276274
gdf_context *join_context) except +
277275

278-
cdef gdf_error gdf_cast(gdf_column *input, gdf_column *output)
276+
cdef gdf_error gdf_cast(gdf_column *input, gdf_column *output) except +
279277

280-
cdef gdf_error gdf_validity_and(gdf_column *lhs, gdf_column *rhs, gdf_column *output)
278+
cdef gdf_error gdf_validity_and(gdf_column *lhs, gdf_column *rhs, gdf_column *output) except +
281279

282-
cdef gdf_error gdf_apply_stencil(gdf_column *lhs, gdf_column * stencil, gdf_column * output)
280+
cdef gdf_error gdf_apply_stencil(gdf_column *lhs, gdf_column * stencil, gdf_column * output) except +
283281

284282
cdef gdf_size_type gdf_dtype_size(gdf_dtype dtype) except +
285283

286-
cdef gdf_error get_column_byte_width(gdf_column * col, int * width)
284+
cdef gdf_error get_column_byte_width(gdf_column * col, int * width) except +
287285

288286
cdef gdf_error gdf_filter(size_t nrows,
289287
gdf_column* cols,
@@ -292,7 +290,7 @@ cdef extern from "cudf.h" nogil:
292290
int* d_types,
293291
void** d_vals,
294292
size_t* d_indx,
295-
size_t* new_sz)
293+
size_t* new_sz) except +
296294

297295
cdef gdf_error gdf_group_by_sum(int ncols,
298296
gdf_column** cols,
@@ -301,7 +299,7 @@ cdef extern from "cudf.h" nogil:
301299
gdf_column** out_col_values,
302300

303301
gdf_column* out_col_agg,
304-
gdf_context* ctxt)
302+
gdf_context* ctxt) except +
305303

306304
cdef gdf_error gdf_group_by_min(int ncols,
307305
gdf_column** cols,
@@ -310,7 +308,7 @@ cdef extern from "cudf.h" nogil:
310308
gdf_column** out_col_values,
311309

312310
gdf_column* out_col_agg,
313-
gdf_context* ctxt)
311+
gdf_context* ctxt) except +
314312

315313

316314
cdef gdf_error gdf_group_by_max(int ncols,
@@ -320,7 +318,7 @@ cdef extern from "cudf.h" nogil:
320318
gdf_column** out_col_values,
321319

322320
gdf_column* out_col_agg,
323-
gdf_context* ctxt)
321+
gdf_context* ctxt) except +
324322

325323

326324
cdef gdf_error gdf_group_by_avg(int ncols,
@@ -330,7 +328,7 @@ cdef extern from "cudf.h" nogil:
330328
gdf_column** out_col_values,
331329

332330
gdf_column* out_col_agg,
333-
gdf_context* ctxt)
331+
gdf_context* ctxt) except +
334332

335333
cdef gdf_error gdf_group_by_count(int ncols,
336334
gdf_column** cols,
@@ -339,7 +337,7 @@ cdef extern from "cudf.h" nogil:
339337
gdf_column** out_col_values,
340338

341339
gdf_column* out_col_agg,
342-
gdf_context* ctxt)
340+
gdf_context* ctxt) except +
343341

344342

345343
cdef gdf_error gdf_quantile_exact(gdf_column* col_in,
@@ -357,17 +355,17 @@ cdef extern from "cudf.h" nogil:
357355

358356
cdef gdf_error gdf_find_and_replace_all(gdf_column* col,
359357
gdf_column* old_values,
360-
gdf_column* new_values)
358+
gdf_column* new_values) except +
361359

362360

363361
cdef gdf_error gdf_replace_nulls(gdf_column* col_out,
364-
const gdf_column* col_in)
362+
const gdf_column* col_in) except +
365363

366364

367365
cdef gdf_error gdf_digitize(gdf_column* col,
368366
gdf_column* bins,
369367
bool right,
370-
gdf_index_type* out_indices)
368+
gdf_index_type* out_indices) except +
371369

372370
cdef gdf_error gdf_from_dlpack(gdf_column** columns,
373371
gdf_size_type *num_columns,
@@ -386,4 +384,4 @@ cdef extern from "cudf.h" nogil:
386384

387385
cdef extern from "bitmask.hpp" nogil:
388386

389-
cdef gdf_error gdf_count_nonzero_mask(gdf_valid_type * masks, int num_rows, int * count)
387+
cdef gdf_error gdf_count_nonzero_mask(gdf_valid_type * masks, int num_rows, int * count) except +

0 commit comments

Comments
 (0)