{"record":{"id":"747fe1cf9828fe73","repo":"pandas-dev/pandas","slug":"other-should-be-pandas-na-or-a-bool-got-type-o","errorCode":null,"errorMessage":"'other' should be pandas.NA or a bool. Got {type(other).__name__} instead.","messagePattern":"'other' should be pandas\\.NA or a bool\\. Got (.+?) instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/boolean.py","lineNumber":421,"sourceCode":"            ) and not ops.has_castable_attr(other):\n                warnings.warn(\n                    f\"Operation with {type(other).__name__} is deprecated. \"\n                    \"In a future version these will be treated as scalar-like. \"\n                    \"To retain the old behavior, explicitly wrap in a Series \"\n                    \"instead.\",\n                    Pandas4Warning,\n                    stacklevel=find_stack_level(),\n                )\n\n            other = np.asarray(other, dtype=\"bool\")\n            if other.ndim > 1:\n                return NotImplemented\n            other, mask = coerce_to_array(other, copy=False)\n        elif isinstance(other, np.bool_):\n            other = other.item()\n\n        if other_is_scalar and other is not libmissing.NA and not lib.is_bool(other):\n            raise TypeError(\n                \"'other' should be pandas.NA or a bool. \"\n                f\"Got {type(other).__name__} instead.\"\n            )\n\n        if not other_is_scalar and len(self) != len(other):\n            raise ValueError(\"Lengths must match\")\n\n        if op.__name__ in {\"or_\", \"ror_\"}:\n            result, mask = ops.kleene_or(self._data, other, self._mask, mask)\n        elif op.__name__ in {\"and_\", \"rand_\"}:\n            result, mask = ops.kleene_and(self._data, other, self._mask, mask)\n        else:\n            # i.e. xor, rxor\n            result, mask = ops.kleene_xor(self._data, other, self._mask, mask)\n\n        # i.e. BooleanArray\n        return self._maybe_mask_result(result, mask)\n","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/boolean.py#L403-L439","documentation":"Raised by BooleanArray._logical_method when the 'other' operand is a scalar that is neither pandas.NA nor a Python bool. Boolean logical ops (and/or/xor with Kleene logic) only accept NA, True, False, or array-likes of bool; any other scalar type (int, str, float) is rejected to avoid silent truthiness coercion.","triggerScenarios":"boolean_series & 1; boolean_series | 'yes'; boolean_array ^ 0.5. Reached through &, |, ^ operators and their reflected variants on a BooleanArray-backed Series.","commonSituations":"Using 0/1 integers instead of True/False; passing strings that look boolean; mixing nullable boolean Series with non-bool scalars in vectorized expressions.","solutions":["Convert the scalar to a bool (or pd.NA) before the operation: bool(other).","If you have 0/1 integers, wrap as a BooleanArray-aligned operand: pd.array([1,0,1], dtype='boolean').","Use .astype('boolean') on an integer Series before combining with a BooleanArray Series."],"exampleFix":"// before\ns = pd.array([True, False, None], dtype='boolean')\nout = s & 1\n// after\nout = s & True","handlingStrategy":"type-guard","validationCode":"from pandas._libs import lib\nfrom pandas import NA\nif lib.is_scalar(other) and other is not NA and not lib.is_bool(other):\n    raise TypeError(f'other must be NA or bool, got {type(other).__name__}')","typeGuard":"def is_bool_or_na(x) -> bool:\n    from pandas._libs import lib\n    from pandas import NA\n    return x is NA or (lib.is_scalar(x) and lib.is_bool(x))","tryCatchPattern":"try:\n    result = boolean_array & other\nexcept TypeError as e:\n    if \"should be pandas.NA or a bool\" in str(e):\n        other = bool(other)\n        ...","preventionTips":["Use True/False/pd.NA as scalar operands with BooleanArray.","Convert 0/1 to bool before combining."],"tags":["boolean","logical","kleene","operator","scalar"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}