Skip to content

Commit 5909621

Browse files
authored
BUG: Fix RecursionError when apply native container types as a func (#61615)
BUG: Fix RecursionError when apply native container types as a func (#61565)
1 parent 8b3bd48 commit 5909621

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ Other
887887
- Bug in :func:`eval` with ``engine="numexpr"`` returning unexpected result for float division. (:issue:`59736`)
888888
- Bug in :func:`to_numeric` raising ``TypeError`` when ``arg`` is a :class:`Timedelta` or :class:`Timestamp` scalar. (:issue:`59944`)
889889
- Bug in :func:`unique` on :class:`Index` not always returning :class:`Index` (:issue:`57043`)
890+
- Bug in :meth:`DataFrame.apply` raising ``RecursionError`` when passing ``func=list[int]``. (:issue:`61565`)
890891
- Bug in :meth:`DataFrame.apply` where passing ``engine="numba"`` ignored ``args`` passed to the applied function (:issue:`58712`)
891892
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which caused an exception when using NumPy attributes via ``@`` notation, e.g., ``df.eval("@np.floor(a)")``. (:issue:`58041`)
892893
- Bug in :meth:`DataFrame.eval` and :meth:`DataFrame.query` which did not allow to use ``tan`` function. (:issue:`55091`)

pandas/_libs/lib.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ from collections import abc
22
from decimal import Decimal
33
from enum import Enum
44
from sys import getsizeof
5+
from types import GenericAlias
56
from typing import (
67
Literal,
78
_GenericAlias,
@@ -1298,7 +1299,7 @@ cdef bint c_is_list_like(object obj, bint allow_sets) except -1:
12981299
getattr(obj, "__iter__", None) is not None and not isinstance(obj, type)
12991300
# we do not count strings/unicode/bytes as list-like
13001301
# exclude Generic types that have __iter__
1301-
and not isinstance(obj, (str, bytes, _GenericAlias))
1302+
and not isinstance(obj, (str, bytes, _GenericAlias, GenericAlias))
13021303
# exclude zero-dimensional duck-arrays, effectively scalars
13031304
and not (hasattr(obj, "ndim") and obj.ndim == 0)
13041305
# exclude sets if allow_sets is False

pandas/tests/dtypes/test_inference.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ class MyDataFrame(DataFrame, Generic[T]): ...
250250
assert inference.is_list_like(tst)
251251

252252

253+
def test_is_list_like_native_container_types():
254+
# GH 61565
255+
# is_list_like was yielding false positives for native container types
256+
assert not inference.is_list_like(list[int])
257+
assert not inference.is_list_like(list[str])
258+
assert not inference.is_list_like(tuple[int])
259+
assert not inference.is_list_like(tuple[str])
260+
261+
253262
def test_is_sequence():
254263
is_seq = inference.is_sequence
255264
assert is_seq((1, 2))

0 commit comments

Comments
 (0)