Skip to content

Commit d71d1ba

Browse files
Daniel SaxtonDaniel Saxton
Daniel Saxton
authored and
Daniel Saxton
committed
Don't raise with nullable boolean
1 parent 2441b40 commit d71d1ba

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

pandas/core/common.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def is_bool_indexer(key: Any) -> bool:
114114
check_array_indexer : Check that `key` is a valid array to index,
115115
and convert to an ndarray.
116116
"""
117-
na_msg = "cannot mask with array containing NA / NaN values"
118117
if isinstance(key, (ABCSeries, np.ndarray, ABCIndex)) or (
119118
is_array_like(key) and is_extension_array_dtype(key.dtype)
120119
):
@@ -127,11 +126,6 @@ def is_bool_indexer(key: Any) -> bool:
127126
return False
128127
return True
129128
elif is_bool_dtype(key.dtype):
130-
# an ndarray with bool-dtype by definition has no missing values.
131-
# So we only need to check for NAs in ExtensionArrays
132-
if is_extension_array_dtype(key.dtype):
133-
if np.any(key.isna()):
134-
raise ValueError(na_msg)
135129
return True
136130
elif isinstance(key, list):
137131
try:

pandas/core/indexing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from pandas.util._decorators import Appender
99

1010
from pandas.core.dtypes.common import (
11+
is_bool_dtype,
12+
is_extension_array_dtype,
1113
is_float,
1214
is_integer,
1315
is_iterator,
@@ -2229,6 +2231,11 @@ def check_bool_indexer(index: Index, key) -> np.ndarray:
22292231
"the indexed object do not match)."
22302232
)
22312233
result = result.astype(bool)._values
2234+
elif is_extension_array_dtype(key) and is_bool_dtype(key):
2235+
mask = isna(key)
2236+
if mask.any():
2237+
result[mask] = False
2238+
result = np.asarray(result, dtype=bool)
22322239
else:
22332240
# key might be sparse / object-dtype bool, check_array_indexer needs bool array
22342241
result = np.asarray(result, dtype=bool)

0 commit comments

Comments
 (0)