Skip to content

Commit 4eea08e

Browse files
committed
Handle list with NA
1 parent c073c0b commit 4eea08e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pandas/core/generic.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
from pandas._libs import lib
3030
from pandas._libs.lib import is_range_indexer
31+
from pandas._libs.missing import NA
3132
from pandas._libs.tslibs import (
3233
Period,
3334
Timestamp,
@@ -10099,6 +10100,21 @@ def mask(
1009910100
if not hasattr(cond, "__invert__"):
1010010101
cond = np.array(cond)
1010110102

10103+
if isinstance(cond, np.ndarray):
10104+
if all(
10105+
np.apply_along_axis(
10106+
lambda x: x[0] is NA
10107+
or isinstance(x[0], (np.bool_, bool))
10108+
or x[0] is np.nan,
10109+
axis=1,
10110+
arr=cond.flatten().reshape(cond.size, 1),
10111+
)
10112+
):
10113+
if not cond.flags.writeable:
10114+
cond.setflags(write=1)
10115+
cond[isna(cond)] = False
10116+
cond = cond.astype(bool)
10117+
1010210118
return self._where(
1010310119
~cond,
1010410120
other=other,

0 commit comments

Comments
 (0)