From f4fb14c44a8219b3215e0cbf54eaa231572212de Mon Sep 17 00:00:00 2001 From: Licht-T Date: Mon, 7 May 2018 09:26:25 +0900 Subject: [PATCH 1/3] BUG: Fix isna cannot handle ambiguous typed list --- pandas/core/dtypes/missing.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 From 665b1fd8a93fcb54b2bd157fc2d52f174712bb7d Mon Sep 17 00:00:00 2001 From: Licht-T Date: Mon, 7 May 2018 09:30:45 +0900 Subject: [PATCH 2/3] TST: Add test of isna evaluation with ambiguous typed list --- pandas/tests/dtypes/test_missing.py | 5 +++++ 1 file changed, 5 insertions(+) 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]) From 9b87fe7b67282f94fb1e9f43845d1048d7c3bc24 Mon Sep 17 00:00:00 2001 From: Licht-T Date: Mon, 7 May 2018 22:34:38 +0900 Subject: [PATCH 3/3] DOC: Add whatsnew note --- doc/source/whatsnew/v0.23.0.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 979fbb5ddfdd0..47fb0b89ef6a8 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -1356,6 +1356,7 @@ Reshaping - Bug in :meth:`DataFrame.astype` where column metadata is lost when converting to categorical or a dictionary of dtypes (:issue:`19920`) - 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:`isna`, which cannot handle ambiguous typed lists (:issue:`20675`) Other ^^^^^