{"record":{"id":"0ca8eed922f37933","repo":"pandas-dev/pandas","slug":"operator-op-name-not-implemented-for-bool-dtyp","errorCode":null,"errorMessage":"operator '{op_name}' not implemented for bool dtypes","messagePattern":"operator '(.+?)' not implemented for bool dtypes","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/masked.py","lineNumber":1017,"sourceCode":"            #  e.g. test_array_scalar_like_equivalence\n            other = bool(other)\n\n        mask = self._propagate_mask(omask, other)\n\n        if other is libmissing.NA:\n            result = np.ones_like(self._data)\n            if self.dtype.kind == \"b\":\n                if op_name in {\n                    \"floordiv\",\n                    \"rfloordiv\",\n                    \"pow\",\n                    \"rpow\",\n                    \"truediv\",\n                    \"rtruediv\",\n                }:\n                    # GH#41165 Try to match non-masked Series behavior\n                    #  This is still imperfect GH#46043\n                    raise NotImplementedError(\n                        f\"operator '{op_name}' not implemented for bool dtypes\"\n                    )\n                if op_name in {\"mod\", \"rmod\"}:\n                    dtype = \"int8\"\n                else:\n                    dtype = \"bool\"\n                result = result.astype(dtype)\n            elif \"truediv\" in op_name and self.dtype.kind != \"f\":\n                # The actual data here doesn't matter since the mask\n                #  will be all-True, but since this is division, we want\n                #  to end up with floating dtype.\n                result = result.astype(np.float64)\n            elif op_name in {\"divmod\", \"rdivmod\"}:\n                # GH#62196\n                res = self._maybe_mask_result(result, mask)\n                return res, res.copy()\n        else:\n            # Make sure we do this before the \"pow\" mask checks","sourceCodeStart":999,"sourceCodeEnd":1035,"githubUrl":"https://github.com/pandas-dev/pandas/blob/71959b8cb9b2459c16e14b34f28b178ccfe14735/pandas/core/arrays/masked.py#L999-L1035","documentation":"Raised inside BaseMaskedArray._arith_method when the other operand is pandas.NA (or pd.NA-equivalent) and self.dtype is boolean, for the operators floordiv/rfloordiv/pow/rpow/truediv/rtruediv. These arithmetic combinations have no sensible result for booleans, so pandas raises NotImplementedError rather than inventing behavior (see GH#41165).","triggerScenarios":"Computing bool_arr // pd.NA, bool_arr ** pd.NA, bool_arr / pd.NA (and the reflected variants) on a nullable BooleanArray.","commonSituations":"Generic NA-propagating code that applies the same arithmetic op to every column including boolean columns; using .floordiv(pd.NA) or division on a BooleanArray.","solutions":["Skip boolean columns when applying NA-propagating arithmetic; guard on dtype.kind == 'b'.","Cast the BooleanArray to int8/Int8 first if integer division semantics are acceptable: bool_arr.astype('Int8') // pd.NA.","Handle the boolean case explicitly (e.g. produce all-NA via np.full(len(arr), pd.NA))."],"exampleFix":"// before\nres = bool_arr // pd.NA  # raises: operator 'floordiv' not implemented for bool dtypes\n\n// after\nres = bool_arr.astype(\"Int8\") // pd.NA","handlingStrategy":"type-guard","validationCode":"BOOL_NA_OPS = {\"floordiv\", \"rfloordiv\", \"pow\", \"rpow\", \"truediv\", \"rtruediv\"}\n\ndef bool_dtype_safe_op(arr, op_name, other):\n    if arr.dtype.kind == \"b\" and op_name in BOOL_NA_OPS and other is pd.NA:\n        raise NotImplementedError(f\"{op_name} unsupported for bool with NA\")\n    return getattr(arr, f\"__{op_name}__\")(other)","typeGuard":"def is_bool_na_arith(arr, op_name, other) -> bool:\n    import pandas as pd\n    return arr.dtype.kind == \"b\" and other is pd.NA and op_name in {\"floordiv\",\"rfloordiv\",\"pow\",\"rpow\",\"truediv\",\"rtruediv\"}","tryCatchPattern":"try:\n    res = bool_arr // pd.NA\nexcept NotImplementedError as e:\n    if \"not implemented for bool dtypes\" in str(e):\n        res = bool_arr.astype(\"Int8\") // pd.NA\n    else:\n        raise","preventionTips":["Skip boolean columns when applying NA-propagating arithmetic generically.","Cast BooleanArray to Int8 before floor-div/power with NA.","Document which ops are undefined for boolean + NA."],"tags":["masked-array","arithmetic","boolean","na"],"analyzedSha":"71959b8cb9b2459c16e14b34f28b178ccfe14735","analyzedAt":"2026-08-07T01:30:20.476Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}