{"record":{"id":"341045e2b13207a2","repo":"pola-rs/polars","slug":"series-of-type-self-dtype-does-not-have-op-ope","errorCode":null,"errorMessage":"Series of type {self.dtype} does not have {op} operator","messagePattern":"Series of type (.+?) does not have (.+?) operator","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/series/series.py","lineNumber":807,"sourceCode":"            assert f is not None\n            return self._from_pyseries(f(d))\n\n        if isinstance(other, Sequence) and not isinstance(other, str):\n            if self.dtype in (List, Array):\n                other = [other]\n            other = Series(\"\", other)\n            if other.dtype == Null:\n                other.cast(self.dtype)\n\n        if isinstance(other, Series):\n            return self._from_pyseries(getattr(self._s, op)(other._s))\n        try:\n            f = get_ffi_func(op + \"_<>\", self.dtype, self._s)\n        except NotImplementedError:\n            f = None\n        if f is None:\n            msg = f\"Series of type {self.dtype} does not have {op} operator\"\n            raise NotImplementedError(msg)\n        if other is not None:\n            other = maybe_cast(other, self.dtype)\n\n        return self._from_pyseries(f(other))\n\n    @overload  # type: ignore[override]\n    def __eq__(self, other: Expr) -> Expr: ...  # type: ignore[overload-overlap]\n\n    @overload\n    def __eq__(self, other: object) -> Series: ...\n\n    def __eq__(self, other: object) -> Series | Expr:\n        warn_null_comparison(other)\n        if isinstance(other, pl.Expr):\n            return F.lit(self).__eq__(other)\n        return self._comp(other, \"eq\")\n\n    @overload  # type: ignore[override]","sourceCodeStart":789,"sourceCodeEnd":825,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/series/series.py#L789-L825","documentation":"_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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["For nested dtypes, compare a derived primitive form instead: s.list.len() == n, s.struct.field('a') == x, or s.list.join(',') == 'a,b'.","Cast the Series to a comparable dtype before comparing: s.cast(pl.Utf8) == other, or explode List columns and compare elements.","For Object columns, avoid direct comparisons; convert to an explicit dtype at construction, or compare via map_elements with a Python-level predicate.","For whole-row/column equality, use s.equals(other) (DataFrame/Series equality) instead of operator comparison."],"exampleFix":"// before\ns = pl.Series('xs', [[1, 2], [3, 4]])  # dtype List\ns == pl.Series('xs', [[1, 2], [3, 4]])  # NotImplementedError: Series of type List does not have eq operator\n\n// after\ns.list.len() == pl.Series([2, 2])  # or compare exploded elements / struct fields","handlingStrategy":"validation","validationCode":"def supports_comparison(dtype: pl.DataType) -> bool:\n    return not isinstance(dtype, (pl.List, pl.Struct, pl.Object))\nassert supports_comparison(s.dtype), f'{s.dtype} does not support comparison operators; extract fields or cast first'","typeGuard":"def supports_comparison(dtype: pl.DataType) -> bool:\n    return not isinstance(dtype, (pl.List, pl.Struct, pl.Object))","tryCatchPattern":"try:\n    result = s == other\nexcept NotImplementedError as e:\n    if 'does not have' in str(e) and 'operator' in str(e):\n        result = s.cast(pl.Utf8) == str(other)  # or compare struct fields / list elements\n    else:\n        raise","preventionTips":["Avoid direct comparisons on List/Struct/Object dtypes; compare extracted fields (s.struct.field, s.list.explode) instead.","Cast Object-dtype columns to concrete dtypes at creation time rather than comparing raw objects.","Convert nested comparisons to expression form (pl.col(...) == ...) which gives better errors.","Document column dtypes in schemas so nested columns are known before writing filter logic."],"tags":["python","polars","operator-not-supported","nested-dtypes"],"backgroundTag":"unsupported-operation","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}