Skip to content

Commit fc50bde

Browse files
Licht-Tjreback
authored andcommitted
BUG: Fix isna cannot handle ambiguous typed list (#20971)
1 parent da96244 commit fc50bde

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

doc/source/whatsnew/v0.23.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,7 @@ Reshaping
13651365
- Bug in :func:`cut` and :func:`qcut` where timezone information was dropped (:issue:`19872`)
13661366
- Bug in :class:`Series` constructor with a ``dtype=str``, previously raised in some cases (:issue:`19853`)
13671367
- Bug in :func:`get_dummies`, and :func:`select_dtypes`, where duplicate column names caused incorrect behavior (:issue:`20848`)
1368+
- Bug in :func:`isna`, which cannot handle ambiguous typed lists (:issue:`20675`)
13681369

13691370
Other
13701371
^^^^^

pandas/core/dtypes/missing.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ def _isna_new(obj):
120120
return _isna_ndarraylike(obj)
121121
elif isinstance(obj, ABCGeneric):
122122
return obj._constructor(obj._data.isna(func=isna))
123-
elif isinstance(obj, list) or hasattr(obj, '__array__'):
123+
elif isinstance(obj, list):
124+
return _isna_ndarraylike(np.asarray(obj, dtype=object))
125+
elif hasattr(obj, '__array__'):
124126
return _isna_ndarraylike(np.asarray(obj))
125127
else:
126128
return obj is None
@@ -146,7 +148,9 @@ def _isna_old(obj):
146148
return _isna_ndarraylike_old(obj)
147149
elif isinstance(obj, ABCGeneric):
148150
return obj._constructor(obj._data.isna(func=_isna_old))
149-
elif isinstance(obj, list) or hasattr(obj, '__array__'):
151+
elif isinstance(obj, list):
152+
return _isna_ndarraylike_old(np.asarray(obj, dtype=object))
153+
elif hasattr(obj, '__array__'):
150154
return _isna_ndarraylike_old(np.asarray(obj))
151155
else:
152156
return obj is None

pandas/tests/dtypes/test_missing.py

+5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ def test_isna_lists(self):
118118
exp = np.array([False, False])
119119
tm.assert_numpy_array_equal(result, exp)
120120

121+
# GH20675
122+
result = isna([np.NaN, 'world'])
123+
exp = np.array([True, False])
124+
tm.assert_numpy_array_equal(result, exp)
125+
121126
def test_isna_nat(self):
122127
result = isna([NaT])
123128
exp = np.array([True])

0 commit comments

Comments
 (0)