{"record":{"id":"066a8d1b76c903b3","repo":"pandas-dev/pandas","slug":"bad-operand-type-for-unary-self-dtype","errorCode":null,"errorMessage":"bad operand type for unary +: '{self.dtype}'","messagePattern":"bad operand type for unary \\+: '(.+?)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/string_arrow.py","lineNumber":676,"sourceCode":"    def _cmp_method(self, other, op):\n        if (\n            isinstance(other, (BaseStringArray, ArrowExtensionArray))\n            and self.dtype.na_value is not libmissing.NA\n            and other.dtype.na_value is libmissing.NA\n        ):\n            # NA has priority of NaN semantics\n            return NotImplemented\n\n        result = super()._cmp_method(other, op)\n        if self.dtype.na_value is np.nan:\n            if op == operator.ne:\n                return result.to_numpy(np.bool_, na_value=True)\n            else:\n                return result.to_numpy(np.bool_, na_value=False)\n        return result\n\n    def __pos__(self) -> Self:\n        raise TypeError(f\"bad operand type for unary +: '{self.dtype}'\")\n","sourceCodeStart":658,"sourceCodeEnd":677,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/string_arrow.py#L658-L677","documentation":"ArrowStringArray.__pos__ raises TypeError because unary + is meaningless for string data. numpy allows + on numeric arrays; pandas overrides __pos__ to refuse rather than silently return the original or coerce.","triggerScenarios":"+s where s is a string[pyarrow] Series; np.positive(s) on a string column; applying operator.pos to the array.","commonSituations":"Generic numerical transforms that apply unary + to every column; using +x as a no-op copy across mixed-dtype frames.","solutions":["Remove unary + from string column handling.","Guard numeric-only transforms with select_dtypes('number').","If a no-op copy is required, use s.copy() explicitly."],"exampleFix":"// before\n+s  # TypeError on string[pyarrow]\n// after\ns.copy()  # if a copy was intended","handlingStrategy":"type-guard","validationCode":"def safe_unary_pos(s):\n    if pd.api.types.is_string_dtype(s):\n        raise TypeError('unary + not supported for string dtype')\n    return +s","typeGuard":"def unary_pos_safe(series) -> bool:\n    return pd.api.types.is_numeric_dtype(series)","tryCatchPattern":"try:\n    +s\nexcept TypeError as e:\n    if 'unary +' in str(e):\n        s = s.copy()  # if a no-op copy was intended\n    else:\n        raise","preventionTips":["Avoid unary + on string columns.","Use select_dtypes('number') before numeric transforms.","Use s.copy() for explicit no-op copies."],"tags":["pandas","arrow-string-array","unary-operator","operator","dtype"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}