pandas-dev/pandas · error · NotImplementedError

{op.__name__} not implemented for {type(other)}

Error message

{op.__name__} not implemented for {type(other)}

What it means

Raised by ArrowExtensionArray._cmp_method when `other` is neither array-like (ExtensionArray/ndarray/list/range) nor a scalar (is_scalar True). This final else branch catches unexpected comparator operands such as custom Python objects, dicts, or multi-dimensional arrays. It is a defensive NotImplementedError signalling the comparison cannot be dispatched.

Source

Thrown at pandas/core/arrays/arrow/array.py:1127

                # GH#62157 match non-pyarrow behavior
                result = ops.invalid_comparison(self, other, op)
                result = pa.array(result, type=pa.bool_())
            else:
                try:
                    result = pc_func(self._pa_array, self._box_pa(other))
                except (pa.lib.ArrowNotImplementedError, pa.lib.ArrowInvalid):
                    mask = isna(self) | isna(other)
                    valid = ~mask
                    result = np.zeros(len(self), dtype="bool")
                    np_array = np.array(self)
                    try:
                        result[valid] = op(np_array[valid], other)
                    except TypeError:
                        result = ops.invalid_comparison(self, other, op)
                    result = pa.array(result, type=pa.bool_())
                    result = pc.if_else(valid, result, None)
        else:
            raise NotImplementedError(
                f"{op.__name__} not implemented for {type(other)}"
            )
        return ArrowExtensionArray(result)

    def _op_method_error_message(self, other, op) -> str:
        if hasattr(other, "dtype"):
            other_type = f"dtype '{other.dtype}'"
        else:
            other_type = f"object of type {type(other)}"
        return (
            f"operation '{op.__name__}' not supported for "
            f"dtype '{self.dtype}' with {other_type}"
        )

    def _evaluate_op_method(self, other, op, arrow_funcs) -> Self:
        if (
            is_list_like(other)
            and not isinstance(other, (np.ndarray, ExtensionArray, list))

View on GitHub (pinned to 71959b8cb9)

Solutions

  1. Extract a scalar or array before comparing: arr == df['col'].values.
  2. If comparing to a mapping, resolve values explicitly first.
  3. Ensure `other` is a scalar, list, ndarray, range, or ExtensionArray.
  4. Wrap heterogeneous comparisons and handle unsupported operands explicitly.

Example fix

# before
mask = arrow_arr == {'a': 1}  # NotImplementedError
# after
mask = arrow_arr == some_scalar
# or align a Series
mask = (arrow_arr == pd.Series([1,2,3], dtype=arrow_arr.dtype))._pa_array
Defensive patterns

Strategy: type-guard

Validate before calling

from pandas.api.types import is_scalar, is_list_like

def safe_compare(arr, other):
    if not (is_scalar(other) or is_list_like(other) or isinstance(other, (list, range))):
        raise TypeError(f'unsupported comparison operand {type(other)}')
    return arr == other

mask = safe_compare(arrow_arr, operand)

Type guard

from pandas.api.types import is_scalar
import numpy as np
from pandas.arrays import ExtensionArray

def is_comparable_operand(other) -> bool:
    return is_scalar(other) or isinstance(other, (list, range, np.ndarray, ExtensionArray))

Try / catch

try:
    mask = arr == other
except NotImplementedError as e:
    if 'not implemented for' in str(e):
        # coerce to a comparable form
        mask = arr == np.asarray(other)
    else:
        raise

Prevention

When it happens

Trigger: Comparing an ArrowExtensionArray with a dict, a 2-D array, a custom object, or a pandas DataFrame: `arr == {'a':1}`, `arr < some_object`, `arr == df`. is_scalar(dict) is False and dict is not in the array-like isinstance tuple.

Common situations: Passing a mapping as a comparison value expecting per-key lookup; comparing against an unintended object (e.g. a column reference vs a scalar); edge cases with pandas objects whose is_scalar is False.

Related errors


AI-assisted analysis of pandas-dev/pandas@71959b8cb9 (2026-08-07). Data as JSON: /api/errors/860d001829f037da. Report an issue: GitHub.