Skip to content

Commit b828d74

Browse files
authored
BUG: Propagate Python exceptions from c_is_list_like (#33721) (#33723)
1 parent d944132 commit b828d74

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

pandas/_libs/lib.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cdef bint c_is_list_like(object, bint)
1+
cdef bint c_is_list_like(object, bint) except -1

pandas/_libs/lib.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ def is_list_like(obj: object, allow_sets: bool = True) -> bool:
988988
return c_is_list_like(obj, allow_sets)
989989

990990

991-
cdef inline bint c_is_list_like(object obj, bint allow_sets):
991+
cdef inline bint c_is_list_like(object obj, bint allow_sets) except -1:
992992
return (
993993
isinstance(obj, abc.Iterable)
994994
# we do not count strings/unicode/bytes as list-like

pandas/tests/dtypes/test_inference.py

+11
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ def test_is_list_like_disallow_sets(maybe_list_like):
123123
assert inference.is_list_like(obj, allow_sets=False) == expected
124124

125125

126+
def test_is_list_like_recursion():
127+
# GH 33721
128+
# interpreter would crash with with SIGABRT
129+
def foo():
130+
inference.is_list_like([])
131+
foo()
132+
133+
with pytest.raises(RecursionError):
134+
foo()
135+
136+
126137
def test_is_sequence():
127138
is_seq = inference.is_sequence
128139
assert is_seq((1, 2))

0 commit comments

Comments
 (0)