Skip to content

Commit 9544549

Browse files
committed
Update to use numpy iterable
1 parent b67b3a7 commit 9544549

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pandas/_libs/lib.pyx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,11 +1035,9 @@ def is_list_like(obj: object, allow_sets: bool = True) -> bool:
10351035

10361036
cdef inline bint c_is_list_like(object obj, bint allow_sets) except -1:
10371037
return (
1038-
isinstance(obj, abc.Iterable)
1038+
np.iterable(obj)
10391039
# we do not count strings/unicode/bytes as list-like
10401040
and not isinstance(obj, (str, bytes))
1041-
# assume not a 0d array unless there's evidence otherwise
1042-
and getattr(obj, "ndim", 1) != 0
10431041
# exclude sets if allow_sets is False
10441042
and not (allow_sets is False and isinstance(obj, abc.Set))
10451043
)

pandas/tests/dtypes/test_inference.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ def __init__(self, values):
7676
self._values = values
7777

7878
def __iter__(self):
79-
for element in iter(self._values):
80-
yield element
79+
iter_values = iter(self._values)
80+
81+
def it_outer():
82+
for element in iter_values:
83+
yield element
84+
85+
return it_outer()
8186

8287
@property
8388
def ndim(self):

0 commit comments

Comments
 (0)