Skip to content

Commit

Permalink
BUG: Fix isna cannot handle ambiguous typed list (#20971)
Browse files Browse the repository at this point in the history
  • Loading branch information
Licht-T authored and jreback committed May 8, 2018
1 parent da96244 commit fc50bde
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,7 @@ Reshaping
- Bug in :func:`cut` and :func:`qcut` where timezone information was dropped (:issue:`19872`)
- Bug in :class:`Series` constructor with a ``dtype=str``, previously raised in some cases (:issue:`19853`)
- Bug in :func:`get_dummies`, and :func:`select_dtypes`, where duplicate column names caused incorrect behavior (:issue:`20848`)
- Bug in :func:`isna`, which cannot handle ambiguous typed lists (:issue:`20675`)

Other
^^^^^
Expand Down
8 changes: 6 additions & 2 deletions pandas/core/dtypes/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def _isna_new(obj):
return _isna_ndarraylike(obj)
elif isinstance(obj, ABCGeneric):
return obj._constructor(obj._data.isna(func=isna))
elif isinstance(obj, list) or hasattr(obj, '__array__'):
elif isinstance(obj, list):
return _isna_ndarraylike(np.asarray(obj, dtype=object))
elif hasattr(obj, '__array__'):
return _isna_ndarraylike(np.asarray(obj))
else:
return obj is None
Expand All @@ -146,7 +148,9 @@ def _isna_old(obj):
return _isna_ndarraylike_old(obj)
elif isinstance(obj, ABCGeneric):
return obj._constructor(obj._data.isna(func=_isna_old))
elif isinstance(obj, list) or hasattr(obj, '__array__'):
elif isinstance(obj, list):
return _isna_ndarraylike_old(np.asarray(obj, dtype=object))
elif hasattr(obj, '__array__'):
return _isna_ndarraylike_old(np.asarray(obj))
else:
return obj is None
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/dtypes/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ def test_isna_lists(self):
exp = np.array([False, False])
tm.assert_numpy_array_equal(result, exp)

# GH20675
result = isna([np.NaN, 'world'])
exp = np.array([True, False])
tm.assert_numpy_array_equal(result, exp)

def test_isna_nat(self):
result = isna([NaT])
exp = np.array([True])
Expand Down

0 comments on commit fc50bde

Please sign in to comment.