pandas-dev/pandas · error · TypeError
operation ' ' not supported for dtype ' ' with
Error message
operation '{op.__name__}' not supported for dtype '{self.dtype}' with {other_type} What it means
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.
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.
Example fix
# before
s = pd.Series(['1', '2'], dtype="string[pyarrow]")
s + 1 # raises TypeError: operation 'add' not supported for dtype 'string[pyarrow]' with object of type <class 'int'>
# after
s.astype('int64[pyarrow]') + 1 Defensive patterns
Strategy: try-catch
Validate before calling
import pyarrow as pa
def can_apply_op(arr, other, op):
try:
pa_type = arr._pa_array.type
boxed = arr._box_pa(other)
# crude compatibility check: both must be castable to a common type
pa.promote_type(pa_type, boxed.type)
return True
except (pa.ArrowTypeError, pa.ArrowInvalid):
return False Try / catch
try:
result = s + other
except TypeError as e:
if 'not supported for dtype' in str(e):
# attempt a cast to a compatible dtype
result = s.astype('int64[pyarrow]') + other
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Can only string multiply by an integer.
- __invert__ is not supported for string dtypes
- DateOffset is intra-day and cannot be applied to…
- unary '-' not supported for dtype
- empty separator
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/d9220d32e43bde80.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/arrays/arrow/array.py:1211
# want to allow addition between string and large_string types
self_array = self._pa_array
if pa.types.is_string(pa_type) and pa.types.is_large_string(other.type):
self_array = self._pa_array.cast(pa.large_string())
elif pa.types.is_large_string(pa_type) and pa.types.is_string(
other.type
):
other = other.cast(pa.large_string())
sep = pa.scalar("", type=self_array.type)
if isinstance(other, pa.Scalar) and pc.is_null(other).as_py():
other = other.cast(self_array.type)
try:
if op is operator.add:
result = pc.binary_join_element_wise(self_array, other, sep)
elif op is roperator.radd:
result = pc.binary_join_element_wise(other, self_array, sep)
except pa.ArrowNotImplementedError as err:
raise TypeError(
self._op_method_error_message(other_original, op)
) from err
return self._from_pyarrow_array(result)
elif op in [operator.mul, roperator.rmul]:
binary = self._pa_array
integral = other
if not pa.types.is_integer(integral.type):
raise TypeError("Can only string multiply by an integer.")
pa_integral = pc.if_else(pc.less(integral, 0), 0, integral)
result = pc.binary_repeat(binary, pa_integral)
return self._from_pyarrow_array(result)
elif (
pa.types.is_string(other.type)
or pa.types.is_binary(other.type)
or pa.types.is_large_string(other.type)
) and op in [operator.mul, roperator.rmul]:
binary = other
integral = self._pa_arrayView on GitHub (pinned to 3b7651241d)