Skip to content

Commit 852b008

Browse files
committed
BUG: Fix RecursionError when apply native container types as a func (pandas-dev#61565)
1 parent 7d542b4 commit 852b008

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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)