Skip to content

Commit 4cc77f7

Browse files
committed
Fix is_list_like on zero-dim arrays pandas-dev#19011
1 parent e713091 commit 4cc77f7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pandas/core/dtypes/inference.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,15 @@ def is_list_like(obj):
278278
False
279279
>>> is_list_like(1)
280280
False
281+
>>> is_list_like(np.array([2]))
282+
True
283+
>>> is_list_like(np.array(2)))
284+
False
281285
"""
282286

283287
return (isinstance(obj, Iterable) and
284-
not isinstance(obj, string_and_binary_types))
288+
not isinstance(obj, string_and_binary_types) and
289+
not (isinstance(obj, np.ndarray) and obj.ndim == 0))
285290

286291

287292
def is_array_like(obj):

pandas/tests/dtypes/test_inference.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,14 @@ def __getitem__(self):
6767
[
6868
[], [1], (1, ), (1, 2), {'a': 1},
6969
set([1, 'a']), Series([1]),
70-
Series([]), Series(['a']).str])
70+
Series([]), Series(['a']).str,
71+
np.array([2])])
7172
def test_is_list_like_passes(ll):
7273
assert inference.is_list_like(ll)
7374

7475

7576
@pytest.mark.parametrize(
76-
"ll", [1, '2', object(), str])
77+
"ll", [1, '2', object(), str, np.array(2)])
7778
def test_is_list_like_fails(ll):
7879
assert not inference.is_list_like(ll)
7980

0 commit comments

Comments
 (0)