Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 915b8a7

Browse files
committedApr 6, 2025
Prevent a list with np.nan converting to float
1 parent 98fb602 commit 915b8a7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed
 

‎pandas/core/generic.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -9713,11 +9713,13 @@ def _where(
97139713
cond = cond.align(self, join="right")[0]
97149714
else:
97159715
if not hasattr(cond, "shape"):
9716-
cond = np.asanyarray(cond)
9716+
cond = np.asanyarray(cond, dtype=object)
9717+
if not cond.flags.writeable:
9718+
cond.setflags(write=True)
9719+
cond[isna(cond)] = True
97179720
if cond.shape != self.shape:
97189721
raise ValueError("Array conditional must be same shape as self")
97199722
cond = self._constructor(cond, **self._construct_axes_dict(), copy=False)
9720-
cond = cond.fillna(True)
97219723

97229724
# make sure we are boolean
97239725
fill_value = bool(inplace)
@@ -10098,7 +10100,7 @@ def mask(
1009810100

1009910101
# see gh-21891
1010010102
if not hasattr(cond, "__invert__"):
10101-
cond = np.array(cond)
10103+
cond = np.array(cond, dtype=object)
1010210104

1010310105
if isinstance(cond, np.ndarray):
1010410106
if all(

0 commit comments

Comments
 (0)
Please sign in to comment.