{"record":{"id":"d4c27a2a2202b24a","repo":"pandas-dev/pandas","slug":"cannot-pass-mask-for-booleanarray-input","errorCode":null,"errorMessage":"cannot pass mask for BooleanArray input","messagePattern":"cannot pass mask for BooleanArray input","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/boolean.py","lineNumber":201,"sourceCode":"    values, mask=None, copy: bool = False\n) -> tuple[np.ndarray, np.ndarray]:\n    \"\"\"\n    Coerce the input values array to numpy arrays with a mask.\n\n    Parameters\n    ----------\n    values : 1D list-like\n    mask : bool 1D array, optional\n    copy : bool, default False\n        if True, copy the input\n\n    Returns\n    -------\n    tuple of (values, mask)\n    \"\"\"\n    if isinstance(values, BooleanArray):\n        if mask is not None:\n            raise ValueError(\"cannot pass mask for BooleanArray input\")\n        values, mask = values._data, values._mask\n        if copy:\n            values = values.copy()\n            mask = mask.copy()\n        return values, mask\n\n    mask_values = None\n    if isinstance(values, np.ndarray) and values.dtype == np.bool_:\n        if copy:\n            values = values.copy()\n    elif isinstance(values, np.ndarray) and values.dtype.kind in \"iufcb\":\n        mask_values = isna(values)\n\n        values_bool = np.zeros(len(values), dtype=bool)\n        values_bool[~mask_values] = values[~mask_values].astype(bool)\n\n        if not np.all(\n            values_bool[~mask_values].astype(values.dtype) == values[~mask_values]","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/boolean.py#L183-L219","documentation":"Raised by coerce_to_array when values is already a BooleanArray and a separate mask argument is also passed. A BooleanArray already carries its own mask, so supplying another is ambiguous; pandas refuses to silently merge them.","triggerScenarios":"Calling pd.array(boolean_array, mask=..., dtype='boolean'), or BooleanArray(values=existing_boolean_array, mask=...). Also reachable via internal coerce_to_array calls when a BooleanArray is forwarded together with a user-supplied mask.","commonSituations":"Wrapping an existing nullable BooleanArray with an externally computed mask; pipeline code that always passes a mask regardless of input type; refactor that passes BooleanArray where previously an ndarray was used.","solutions":["Drop the mask argument when passing a BooleanArray; rely on its built-in mask.","If you need a different mask, extract the underlying data first: boolean_array._data, then pass mask explicitly.","Combine masks yourself: combined = boolean_array._mask | your_mask, then build BooleanArray(boolean_array._data, combined)."],"exampleFix":"// before\npd.array(existing_bool_array, mask=my_mask, dtype='boolean')\n// after\npd.array(existing_bool_array, dtype='boolean')\n// or\nBooleanArray(existing_bool_array._data, existing_bool_array._mask | my_mask)","handlingStrategy":"validation","validationCode":"if isinstance(values, BooleanArray) and mask is not None:\n    raise ValueError('BooleanArray already has a mask; drop the mask argument')","typeGuard":"def is_boolean_array(v) -> bool:\n    from pandas.core.arrays.boolean import BooleanArray\n    return isinstance(v, BooleanArray)","tryCatchPattern":"try:\n    coerce_to_array(values, mask=mask)\nexcept ValueError as e:\n    if 'cannot pass mask' in str(e):\n        values, mask = values._data, values._mask\n        ...","preventionTips":["Do not pass mask when values is already a BooleanArray.","Extract _data first if you need a custom mask."],"tags":["boolean","mask","coerce","nullable","api-misuse"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}