-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Propagate Python exceptions from c_is_list_like (#33721) #33723
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
Changes from 1 commit
da1f74a
a773ba5
25a0afe
50812d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
cdef bint c_is_list_like(object, bint) | ||
cdef bint c_is_list_like(object, bint) except -1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm don't think a bint can ever return -1. The only thing I think you could except here is NULL but would really have to refactor to do that Is there a particular issue you are trying to solve? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for reviewing. The ignored exception led to a segfault in https://github.com/rapidsai/cudf that I'm unable to reproduce at the moment since we've since refactored our code a bit -- apologies. However, we can demonstrate the issue by raising artificially within
cdef inline bint c_is_list_like(object obj, bint allow_sets):
raise ZeroDivisionError()
return (
isinstance(obj, abc.Iterable)
# we do not count strings/unicode/bytes as list-like
and not isinstance(obj, (str, bytes))
# exclude zero-dimensional numpy arrays, effectively scalars
and not (util.is_array(obj) and obj.ndim == 0)
# exclude sets if allow_sets is False
and not (allow_sets is False and isinstance(obj, abc.Set))
) >>> import pandas as pd
>>> pd.api.types.is_list_like([])
ZeroDivisionError
Exception ignored in: 'pandas._libs.lib.c_is_list_like'
ZeroDivisionError:
False
cdef inline bint c_is_list_like(object obj, bint allow_sets) except -1:
raise ZeroDivisionError()
return (
isinstance(obj, abc.Iterable)
# we do not count strings/unicode/bytes as list-like
and not isinstance(obj, (str, bytes))
# exclude zero-dimensional numpy arrays, effectively scalars
and not (util.is_array(obj) and obj.ndim == 0)
# exclude sets if allow_sets is False
and not (allow_sets is False and isinstance(obj, abc.Set))
) >>> import pandas as pd
>>>pd.api.types.is_list_like([])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pandas/_libs/lib.pyx", line 985, in pandas._libs.lib.is_list_like
return c_is_list_like(obj, allow_sets)
File "pandas/_libs/lib.pyx", line 989, in pandas._libs.lib.c_is_list_like
raise ZeroDivisionError()
ZeroDivisionError ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Any idea what value was being passed? Its hard to imagine what could cause this to raise unless you specifically rigged it to make isinstance checks fail There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha - so after digging up some old code, it looks the source of the problem was a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minimal repro (segfaults for me):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 is appropriate here as it signals cython that there maybe is an exception to check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don’t need the whats new as this is pretty obscure and not user facing