pandas-dev/pandas · error · NotImplementedError
not implemented for
Error message
{op.__name__} not implemented for {type(other)} What it means
Raised by ArrowExtensionArray._cmp_method when the `other` operand of a comparison is neither array-like (ExtensionArray/ndarray/list/range) nor a recognized scalar. This is the terminal else-branch: pandas does not know how to broadcast a comparison against an arbitrary object, so it raises NotImplementedError naming the operand's type.
Solutions
- Convert the operand to a scalar or array-like first: list(other), np.asarray(other), or wrap in a Series.
- If it is a pyarrow Scalar, call .as_py() to get a native Python scalar before comparing.
- Implement __eq__/__lt__ on your custom type returning a comparable scalar.
- Avoid comparing against containers like dict/set that have no elementwise semantics.
Example fix
# before import pyarrow as pa arr = pd.array([1, 2, 3], dtype="int64[pyarrow]") arr == pa.scalar(2) # pa.Scalar is not 'is_scalar' -> NotImplementedError # after arr == pa.scalar(2).as_py()
Defensive patterns
Strategy: type-guard
Validate before calling
import pyarrow as pa
from pandas.api.types import is_scalar, is_list_like
def normalize_operand(other):
if isinstance(other, pa.Scalar):
return other.as_py()
if is_list_like(other) and not isinstance(other, (list, range)):
return list(other)
return other Type guard
import pyarrow as pa
from pandas.api.types import is_scalar
def is_cmp_operand(other) -> bool:
if isinstance(other, pa.Scalar):
return False # must call .as_py() first
return is_scalar(other) or hasattr(other, 'dtype') or isinstance(other, (list, range)) Prevention
- Convert pa.Scalar via .as_py() before comparing.
- Wrap custom objects in a comparable scalar or a list.
- Avoid comparing against dict/set/tuple containers.
When it happens
Trigger: Comparing an ArrowExtensionArray against a custom Python object, a dict, a tuple, a set, or a pyarrow Scalar that escaped the is_scalar check; arr == some_object where some_object.__eq__ does not cooperate.
Common situations: User-defined types passed as comparison operands; passing a row from a DataFrame (a Series) works, but a raw dict/tuple does not; comparing against a pa.Scalar directly.
Related errors
- Can only string multiply by an integer.
- DateOffset is intra-day and cannot be applied to…
- Invalid value ' ' for dtype
- __invert__ is not supported for string dtypes
- operation ' ' not supported for dtype ' ' with
AI-assisted analysis of pandas-dev/pandas@3b7651241d (2026-08-11).
Data as JSON: /api/errors/860d001829f037da.
Report an issue: GitHub.
Appendix: source
Thrown at pandas/core/arrays/arrow/array.py:1152
# 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 3b7651241d)