NVIDIA / NVIDIA/cudf

[FEA] Allow capturing cudf specific exceptions in `cudf.pandas` by using ExceptionGroup in Python 3.11

Open
#14,379 2 comments 0 reactions 0 assignees View on GitHub
cudf.pandas feature request Python
Dominant language
C++
Stars
9.8k
Forks
1.1k
Avg merge
3d 6m
Merged PRs (30d)
278

Description

**Is your feature request related to a problem? Please describe.**
Currently when using `cudf.pandas`, there's no way to capture or act on the cudf exception thrown whether the operation succeeds or fails on during the pandas path.

```python
In [1]: %load_ext cudf.pandas

In [2]: import pandas as pd

In [3]: try:
...: pd.to_datetime("2020-01-01", utc=True)
...: except NotImplementedError:
...: print("hello")

In [4]: import cudf

In [5]: cudf.to_datetime("2020-01-01", utc=True)
NotImplementedError: utc is not yet implemented
```

**Describe the solution you'd like**

If `_fast_slow_function_call` was structured like:

```python
In [8]: def f():
...: try:
...: raise NotImplementedError("fast doesn't work")
...: except Exception as err_fast:
...: try:
...: raise ValueError("Slow doesn't work")
...: except Exception as err_slow:
...: raise ExceptionGroup("Fast and slow did't work", [err_fast, err_slow])
...:

In [9]: f()
Traceback (most recent call last):
File "", line 6, in f
raise ValueError("Slow doesn't work")
ValueError: Slow doesn't work

During handling of the above exception, another exception occurred:

+ Exception Group Traceback (most recent call last):
| File "/opt/miniconda3/envs/pandas-dev/lib/python3.11/site-packages/IPython/core/interactiveshell.py", line 3548, in run_code
| exec(code_obj, self.user_global_ns, self.user_ns)
| File "", line 1, in
| f()
| File "", line 8, in f
| raise ExceptionGroup("Fast and slow did't work", [err_fast, err_slow])
| ExceptionGroup: Fast and slow did't work (2 sub-exceptions)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "", line 3, in f
| raise NotImplementedError("fast doesn't work")
| NotImplementedError: fast doesn't work
+---------------- 2 ----------------
| Traceback (most recent call last):
| File "", line 6, in f
| raise ValueError("Slow doesn't work")
| ValueError: Slow doesn't work
+------------------------------------

In [10]: try:
...: f()
...: except* NotImplementedError:
...: print("Try doing something else")
...:
Try doing something else
+ Exception Group Traceback (most recent call last):
| File "/opt/miniconda3/envs/pandas-dev/lib/python3.11/site-packages/IPython/core/interactiveshell.py", line 3548, in run_code
| exec(code_obj, self.user_global_ns, self.user_ns)
| File "", line 2, in
| f()
| File "", line 8, in f
| raise ExceptionGroup("Fast and slow did't work", [err_fast, err_slow])
| ExceptionGroup: Fast and slow did't work (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "", line 3, in f
| raise NotImplementedError("fast doesn't work")
| NotImplementedError: fast doesn't work
|
| During handling of the above exception, another exception occurred:
|
| Traceback (most recent call last):
| File "", line 6, in f
| raise ValueError("Slow doesn't work")
| ValueError: Slow doesn't work
+------------------------------------
```

**Additional context**

Admittedly I don't have a definitive use case where capturing the cudf exception is necessary, and using ExceptionGroup might break "drop in replacement" potential of `cudf.pandas`, but noting that this is a limitation in the current design

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.