Skip to content

Commit a9069f7

Browse files
committed
CLN: clarify code in com.mask_missing
1 parent 75a8d75 commit a9069f7

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

pandas/core/common.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -359,20 +359,18 @@ def mask_missing(arr, values_to_mask):
359359
if mask is None:
360360
mask = arr == x
361361

362-
# if x is a string and mask is not, then we get a scalar
363-
# return value, which is not good
364-
if not isinstance(mask, np.ndarray):
365-
m = mask
366-
mask = np.empty(arr.shape, dtype=np.bool)
367-
mask.fill(m)
362+
# if x is a string and arr is not, then we get False and we must
363+
# expand the mask to size arr.shape
364+
if np.isscalar(mask):
365+
mask = np.zeros(arr.shape, dtype=bool)
368366
else:
369-
mask = mask | (arr == x)
367+
mask |= arr == x
370368

371369
if na_mask.any():
372370
if mask is None:
373371
mask = isnull(arr)
374372
else:
375-
mask = mask | isnull(arr)
373+
mask |= isnull(arr)
376374

377375
return mask
378376

0 commit comments

Comments
 (0)