pola-rs/polars · error · NotImplementedError

Series of type does not have operator

Error message

Series of type {self.dtype} does not have {op} operator

What it means

_comp resolves a low-level FFI function implementing the requested comparison for the Series' dtype. When no comparison operator exists for that dtype (e.g. List, Struct, Object), it raises NotImplementedError stating the dtype has no such operator. This is Polars saying the comparison is not defined for the column's type, not a value problem.

Solutions

  1. For nested dtypes, compare a derived primitive form instead: s.list.len() == n, s.struct.field('a') == x, or s.list.join(',') == 'a,b'.
  2. Cast the Series to a comparable dtype before comparing: s.cast(pl.Utf8) == other, or explode List columns and compare elements.
  3. For Object columns, avoid direct comparisons; convert to an explicit dtype at construction, or compare via map_elements with a Python-level predicate.
  4. For whole-row/column equality, use s.equals(other) (DataFrame/Series equality) instead of operator comparison.

Example fix

// before
s = pl.Series('xs', [[1, 2], [3, 4]])  # dtype List
s == pl.Series('xs', [[1, 2], [3, 4]])  # NotImplementedError: Series of type List does not have eq operator

// after
s.list.len() == pl.Series([2, 2])  # or compare exploded elements / struct fields
Defensive patterns

Strategy: validation

Validate before calling

def supports_comparison(dtype: pl.DataType) -> bool:
    return not isinstance(dtype, (pl.List, pl.Struct, pl.Object))
assert supports_comparison(s.dtype), f'{s.dtype} does not support comparison operators; extract fields or cast first'

Type guard

def supports_comparison(dtype: pl.DataType) -> bool:
    return not isinstance(dtype, (pl.List, pl.Struct, pl.Object))

Try / catch

try:
    result = s == other
except NotImplementedError as e:
    if 'does not have' in str(e) and 'operator' in str(e):
        result = s.cast(pl.Utf8) == str(other)  # or compare struct fields / list elements
    else:
        raise

Prevention

When it happens

Trigger: Applying ==, !=, <, >, <= or >= between a Series of an uncomparable dtype (List, Struct, Object) and another value, e.g. s_list == other_list, or filtering on nested columns directly.

Common situations: Filtering rows by nested List columns for equality; attempting ordering comparisons on Struct columns loaded from JSON; comparing Object-dtype columns after map_elements; leftover code from pandas where any dtype compared via elementwise Python objects.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/341045e2b13207a2. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/series/series.py:807

            assert f is not None
            return self._from_pyseries(f(d))

        if isinstance(other, Sequence) and not isinstance(other, str):
            if self.dtype in (List, Array):
                other = [other]
            other = Series("", other)
            if other.dtype == Null:
                other.cast(self.dtype)

        if isinstance(other, Series):
            return self._from_pyseries(getattr(self._s, op)(other._s))
        try:
            f = get_ffi_func(op + "_<>", self.dtype, self._s)
        except NotImplementedError:
            f = None
        if f is None:
            msg = f"Series of type {self.dtype} does not have {op} operator"
            raise NotImplementedError(msg)
        if other is not None:
            other = maybe_cast(other, self.dtype)

        return self._from_pyseries(f(other))

    @overload  # type: ignore[override]
    def __eq__(self, other: Expr) -> Expr: ...  # type: ignore[overload-overlap]

    @overload
    def __eq__(self, other: object) -> Series: ...

    def __eq__(self, other: object) -> Series | Expr:
        warn_null_comparison(other)
        if isinstance(other, pl.Expr):
            return F.lit(self).__eq__(other)
        return self._comp(other, "eq")

    @overload  # type: ignore[override]

View on GitHub (pinned to fe841f959e)