{"record":{"id":"d9220d32e43bde80","repo":"pandas-dev/pandas","slug":"operation-op-name-not-supported-for-dtype","errorCode":null,"errorMessage":"operation '{op.__name__}' not supported for dtype '{self.dtype}' with {other_type}","messagePattern":"operation '(.+?)' not supported for dtype '(.+?)' with (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pandas/core/arrays/arrow/array.py","lineNumber":1211,"sourceCode":"                # want to allow addition between string and large_string types\n                self_array = self._pa_array\n                if pa.types.is_string(pa_type) and pa.types.is_large_string(other.type):\n                    self_array = self._pa_array.cast(pa.large_string())\n                elif pa.types.is_large_string(pa_type) and pa.types.is_string(\n                    other.type\n                ):\n                    other = other.cast(pa.large_string())\n\n                sep = pa.scalar(\"\", type=self_array.type)\n                if isinstance(other, pa.Scalar) and pc.is_null(other).as_py():\n                    other = other.cast(self_array.type)\n                try:\n                    if op is operator.add:\n                        result = pc.binary_join_element_wise(self_array, other, sep)\n                    elif op is roperator.radd:\n                        result = pc.binary_join_element_wise(other, self_array, sep)\n                except pa.ArrowNotImplementedError as err:\n                    raise TypeError(\n                        self._op_method_error_message(other_original, op)\n                    ) from err\n                return self._from_pyarrow_array(result)\n            elif op in [operator.mul, roperator.rmul]:\n                binary = self._pa_array\n                integral = other\n                if not pa.types.is_integer(integral.type):\n                    raise TypeError(\"Can only string multiply by an integer.\")\n                pa_integral = pc.if_else(pc.less(integral, 0), 0, integral)\n                result = pc.binary_repeat(binary, pa_integral)\n                return self._from_pyarrow_array(result)\n        elif (\n            pa.types.is_string(other.type)\n            or pa.types.is_binary(other.type)\n            or pa.types.is_large_string(other.type)\n        ) and op in [operator.mul, roperator.rmul]:\n            binary = other\n            integral = self._pa_array","sourceCodeStart":1193,"sourceCodeEnd":1229,"githubUrl":"https://github.com/pandas-dev/pandas/blob/3b7651241d4da534b3559b60ef128e1c34f54116/pandas/core/arrays/arrow/array.py#L1193-L1229","documentation":"Produced by _op_method_error_message and raised (as TypeError) when an arithmetic/string operation between an ArrowExtensionArray and an operand cannot be carried out by pyarrow. The message names the operation, the array dtype, and a description of the other operand's dtype or Python type. It is the user-facing wrapper around pa.ArrowNotImplementedError from _evaluate_op_method.","triggerScenarios":"Adding a non-string to a string[pyarrow] array (e.g. 'a' + 1.5); subtracting strings; bitwise ops on string arrays; arithmetic between incompatible pyarrow numeric types after casting fails; calling + on string[pyarrow] with a list of non-strings after the binary_join fallback also fails.","commonSituations":"Mixed-type arithmetic where the user expected Python-style coercion; pyarrow string inference making formerly-object columns strict; combining a string array with an int/float in an expression; using + for numeric add on a column that came in as string.","solutions":["Cast the array or operand to a compatible dtype before operating: s.astype('int64[pyarrow]') + 1.","For string concatenation ensure both sides are string-typed.","Validate operand types with hasattr(other, 'dtype') and check kind before operating.","Catch TypeError if mixed-type input is expected and fall back to object dtype."],"exampleFix":"# before\ns = pd.Series(['1', '2'], dtype=\"string[pyarrow]\")\ns + 1  # raises TypeError: operation 'add' not supported for dtype 'string[pyarrow]' with object of type <class 'int'>\n\n# after\ns.astype('int64[pyarrow]') + 1","handlingStrategy":"try-catch","validationCode":"import pyarrow as pa\n\ndef can_apply_op(arr, other, op):\n    try:\n        pa_type = arr._pa_array.type\n        boxed = arr._box_pa(other)\n        # crude compatibility check: both must be castable to a common type\n        pa.promote_type(pa_type, boxed.type)\n        return True\n    except (pa.ArrowTypeError, pa.ArrowInvalid):\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    result = s + other\nexcept TypeError as e:\n    if 'not supported for dtype' in str(e):\n        # attempt a cast to a compatible dtype\n        result = s.astype('int64[pyarrow]') + other\n    else:\n        raise","preventionTips":["Cast string columns to numeric pyarrow dtypes before arithmetic.","Ensure both operands of string concatenation are string-typed.","Catch TypeError around mixed-type arithmetic and fall back to object dtype."],"tags":["arithmetic","operator","type-validation","pyarrow","string"],"backgroundTag":null,"analyzedSha":"3b7651241d4da534b3559b60ef128e1c34f54116","analyzedAt":"2026-08-11T22:10:44.015Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}