From da1f74a8a87100c00ae9d307146db75106e6fa67 Mon Sep 17 00:00:00 2001 From: Ashwin Srinath Date: Wed, 22 Apr 2020 09:42:19 -0400 Subject: [PATCH 1/3] BUG: Propagate Python exceptions from c_is_list_like (#33721) --- doc/source/whatsnew/v1.1.0.rst | 2 ++ pandas/_libs/lib.pxd | 2 +- pandas/_libs/lib.pyx | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 07849702c646d..8a36f3b1b12f2 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -659,6 +659,8 @@ Other - Bug in :meth:`Series.map` not raising on invalid ``na_action`` (:issue:`32815`) - Bug in :meth:`DataFrame.__dir__` caused a segfault when using unicode surrogates in a column name (:issue:`25509`) - Bug in :meth:`DataFrame.plot.scatter` caused an error when plotting variable marker sizes (:issue:`32904`) +- Propagate Python exceptions from :func:`_lib.c_is_list_like` (#33721) +- .. --------------------------------------------------------------------------- diff --git a/pandas/_libs/lib.pxd b/pandas/_libs/lib.pxd index 12aca9dabe2e7..b3c72c30a74de 100644 --- a/pandas/_libs/lib.pxd +++ b/pandas/_libs/lib.pxd @@ -1 +1 @@ -cdef bint c_is_list_like(object, bint) +cdef bint c_is_list_like(object, bint) except -1 diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index bbb4d562b8971..34a78d63af8b8 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -985,7 +985,7 @@ def is_list_like(obj: object, allow_sets: bool = True) -> bool: return c_is_list_like(obj, allow_sets) -cdef inline bint c_is_list_like(object obj, bint allow_sets): +cdef inline bint c_is_list_like(object obj, bint allow_sets) except -1: return ( isinstance(obj, abc.Iterable) # we do not count strings/unicode/bytes as list-like From a773ba5321f4a6919edb246c15ac3b156a9017ae Mon Sep 17 00:00:00 2001 From: Ashwin Srinath Date: Thu, 23 Apr 2020 12:48:03 -0400 Subject: [PATCH 2/3] Remove whatsnew entry --- doc/source/whatsnew/v1.1.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v1.1.0.rst b/doc/source/whatsnew/v1.1.0.rst index 8a36f3b1b12f2..f31372a24999c 100644 --- a/doc/source/whatsnew/v1.1.0.rst +++ b/doc/source/whatsnew/v1.1.0.rst @@ -659,7 +659,6 @@ Other - Bug in :meth:`Series.map` not raising on invalid ``na_action`` (:issue:`32815`) - Bug in :meth:`DataFrame.__dir__` caused a segfault when using unicode surrogates in a column name (:issue:`25509`) - Bug in :meth:`DataFrame.plot.scatter` caused an error when plotting variable marker sizes (:issue:`32904`) -- Propagate Python exceptions from :func:`_lib.c_is_list_like` (#33721) - .. --------------------------------------------------------------------------- From 25a0afeec97fd6cbe46b91d06cbe9ea7b5f055dc Mon Sep 17 00:00:00 2001 From: Ashwin Srinath Date: Fri, 24 Apr 2020 11:51:23 -0400 Subject: [PATCH 3/3] Add test for recursion error thrown from is_list_like() --- pandas/tests/dtypes/test_inference.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 8c0580b7cf047..3d328c07be353 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -123,6 +123,17 @@ def test_is_list_like_disallow_sets(maybe_list_like): assert inference.is_list_like(obj, allow_sets=False) == expected +def test_is_list_like_recursion(): + # GH 33721 + # interpreter would crash with with SIGABRT + def foo(): + inference.is_list_like([]) + foo() + + with pytest.raises(RecursionError): + foo() + + def test_is_sequence(): is_seq = inference.is_sequence assert is_seq((1, 2))