pandas.api.indexers.
check_bool_array_indexer
Check if mask is a valid boolean indexer for array.
array and mask are checked to have the same length, and the dtype is validated.
New in version 1.0.0.
The array that’s being masked.
The boolean array that’s masking.
The validated boolean mask.
When the lengths don’t match.
When mask cannot be converted to a bool-dtype ndarray.
See also
api.types.is_bool_dtype
Check if key is of boolean dtype.
Examples
A boolean ndarray is returned when the arguments are all valid.
>>> mask = pd.array([True, False]) >>> arr = pd.array([1, 2]) >>> pd.api.extensions.check_bool_array_indexer(arr, mask) array([ True, False])
An IndexError is raised when the lengths don’t match.
>>> mask = pd.array([True, False, True]) >>> pd.api.extensions.check_bool_array_indexer(arr, mask) Traceback (most recent call last): ... IndexError: Item wrong length 3 instead of 2.
A ValueError is raised when the mask cannot be converted to a bool-dtype ndarray.
>>> mask = pd.array([True, pd.NA]) >>> pd.api.extensions.check_bool_array_indexer(arr, mask) Traceback (most recent call last): ... ValueError: cannot convert to bool numpy array in presence of missing values