diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 05e0028047941..078a733a67a3e 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -1364,6 +1364,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 ^^^^^ diff --git a/pandas/core/dtypes/missing.py b/pandas/core/dtypes/missing.py index 3b2336bf19547..d9dc73434f5ac 100644 --- a/pandas/core/dtypes/missing.py +++ b/pandas/core/dtypes/missing.py @@ -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 @@ -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 diff --git a/pandas/tests/dtypes/test_missing.py b/pandas/tests/dtypes/test_missing.py index 365d8d762d673..ca9a2dc81fcc6 100644 --- a/pandas/tests/dtypes/test_missing.py +++ b/pandas/tests/dtypes/test_missing.py @@ -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])