Skip to content

Commit acac5eb

Browse files
authored
Fix issue pandas-dev#47101
Bisecting two years ago ( pandas-dev#47101 (comment) ) shows this regression was introduced in b2d54d9 in 2021. Somehow this hasn't been patched since then. PR pandas-dev#48313 was supposed to address this, but the PR was closed and never merged and the bug has persisted.
1 parent 96d732e commit acac5eb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pandas/core/missing.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,15 @@ def mask_missing(arr: ArrayLike, values_to_mask) -> npt.NDArray[np.bool_]:
124124
new_mask = np.zeros(arr.shape, dtype=np.bool_)
125125
new_mask[arr_mask] = arr[arr_mask] == x
126126
else:
127-
new_mask = arr == x
127+
# GH#47101
128+
# Fix where type 'bool' has no attribute 'to_numpy()' by first attempting to broadcast
129+
# with np.equal for some cases, and then an explicit type check when checking the mask
130+
# for any straggling cases
131+
new_mask = np.equal(arr, x)
128132

129133
if not isinstance(new_mask, np.ndarray):
130134
# usually BooleanArray
131-
new_mask = new_mask.to_numpy(dtype=bool, na_value=False)
135+
new_mask = np.array([new_mask]) if isinstance(new_mask, bool) else new_mask.to_numpy(dtype=bool, na_value=False)
132136
mask |= new_mask
133137

134138
if na_mask.any():

0 commit comments

Comments
 (0)