Skip to content

Commit

Permalink
Fix is_list_like on zero-dim arrays pandas-dev#19011
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel committed Jul 11, 2018
1 parent e713091 commit 4cc77f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pandas/core/dtypes/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,15 @@ def is_list_like(obj):
False
>>> is_list_like(1)
False
>>> is_list_like(np.array([2]))
True
>>> is_list_like(np.array(2)))
False
"""

return (isinstance(obj, Iterable) and
not isinstance(obj, string_and_binary_types))
not isinstance(obj, string_and_binary_types) and
not (isinstance(obj, np.ndarray) and obj.ndim == 0))


def is_array_like(obj):
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ def __getitem__(self):
[
[], [1], (1, ), (1, 2), {'a': 1},
set([1, 'a']), Series([1]),
Series([]), Series(['a']).str])
Series([]), Series(['a']).str,
np.array([2])])
def test_is_list_like_passes(ll):
assert inference.is_list_like(ll)


@pytest.mark.parametrize(
"ll", [1, '2', object(), str])
"ll", [1, '2', object(), str, np.array(2)])
def test_is_list_like_fails(ll):
assert not inference.is_list_like(ll)

Expand Down

0 comments on commit 4cc77f7

Please sign in to comment.