{"record":{"id":"9976541a40e8865f","repo":"pandas-dev/pandas","slug":"values-should-be-boolean-numpy-array-use-the-pd","errorCode":null,"errorMessage":"values should be boolean numpy array. Use the 'pd.array' function instead","messagePattern":"values should be boolean numpy array\\. Use the 'pd\\.array' function instead","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/boolean.py","lineNumber":340,"sourceCode":"    <BooleanArray>\n    [True, False, <NA>]\n    Length: 3, dtype: boolean\n    \"\"\"\n\n    _TRUE_VALUES = {\"True\", \"TRUE\", \"true\", \"1\", \"1.0\"}\n    _FALSE_VALUES = {\"False\", \"FALSE\", \"false\", \"0\", \"0.0\"}\n\n    @classmethod\n    def _simple_new(cls, values: np.ndarray, mask: npt.NDArray[np.bool_]) -> Self:\n        result = super()._simple_new(values, mask)\n        result._dtype = BooleanDtype()\n        return result\n\n    def __init__(\n        self, values: np.ndarray, mask: np.ndarray, copy: bool = False\n    ) -> None:\n        if not (isinstance(values, np.ndarray) and values.dtype == np.bool_):\n            raise TypeError(\n                \"values should be boolean numpy array. Use \"\n                \"the 'pd.array' function instead\"\n            )\n        self._dtype = BooleanDtype()\n        super().__init__(values, mask, copy=copy)\n\n    @property\n    def dtype(self) -> BooleanDtype:\n        return self._dtype\n\n    @classmethod\n    def _from_sequence_of_strings(\n        cls,\n        strings: list[str],\n        *,\n        dtype: ExtensionDtype,\n        copy: bool = False,\n        true_values: list[str] | None = None,","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/boolean.py#L322-L358","documentation":"Raised by BooleanArray.__init__ when values is not a numpy array of dtype bool_. BooleanArray is the low-level constructor expecting two aligned numpy bool arrays; using it with a Python list, an int array, or a pandas object triggers this guard. The message redirects users to pd.array(...) which handles coercion.","triggerScenarios":"Calling pd.BooleanArray([True, False], mask=...) directly; BooleanArray(np.array([1, 0]), mask=...); BooleanArray with a list, tuple, or ExtensionArray as values.","commonSituations":"Users reaching for the low-level BooleanArray constructor instead of the public pd.array(..., dtype='boolean'); passing integer 0/1 numpy arrays directly; copy-pasted code that assumed BooleanArray accepts list input.","solutions":["Use pd.array(values, dtype='boolean') for general construction — it runs coerce_to_array for you.","If you must use BooleanArray directly, convert first: BooleanArray(np.asarray(values, dtype=bool), np.asarray(mask, dtype=bool)).","For 0/1 integer arrays, run coerce_to_array to obtain (values, mask) then construct."],"exampleFix":"// before\npd.BooleanArray([True, False, None], mask=[False, False, True])\n// after\npd.array([True, False, None], dtype='boolean')","handlingStrategy":"validation","validationCode":"import numpy as np\nassert isinstance(values, np.ndarray) and values.dtype == np.bool_, 'use pd.array(..., dtype=\"boolean\") instead'","typeGuard":"def is_bool_ndarray(v) -> bool:\n    import numpy as np\n    return isinstance(v, np.ndarray) and v.dtype == np.bool_","tryCatchPattern":"try:\n    pd.BooleanArray(values, mask)\nexcept TypeError as e:\n    if \"should be boolean numpy array\" in str(e):\n        values = np.asarray(values, dtype=bool)\n        ...","preventionTips":["Prefer pd.array(...) over the low-level BooleanArray constructor.","Convert values to np.bool_ before calling BooleanArray directly."],"tags":["boolean","constructor","numpy","api-misuse","pd-array"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}