Skip to content

Commit 8bac997

Browse files
committed
Fill True when tuple or list cond has np.nan/pd.NA
1 parent b6bd3af commit 8bac997

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pandas/core/generic.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9698,15 +9698,19 @@ def _where(
96989698
if axis is not None:
96999699
axis = self._get_axis_number(axis)
97009700

9701+
cond = common.apply_if_callable(cond, self)
9702+
97019703
# We should not be filling NA. See GH#60729
97029704
if isinstance(cond, np.ndarray):
97039705
cond = np.array(cond)
9704-
cond[np.isnan(cond)] = True
9706+
cond[isna(cond)] = True
97059707
elif isinstance(cond, NDFrame):
97069708
cond = cond.fillna(True)
9709+
elif isinstance(cond, (list, tuple)):
9710+
cond = np.array(cond)
9711+
cond[isna(cond)] = True
97079712

97089713
# align the cond to same shape as myself
9709-
cond = common.apply_if_callable(cond, self)
97109714
if isinstance(cond, NDFrame):
97119715
# CoW: Make sure reference is not kept alive
97129716
if cond.ndim == 1 and self.ndim == 2:

0 commit comments

Comments
 (0)