{"record":{"id":"a2e811a605cf0708","repo":"pola-rs/polars","slug":"operator-r-comparison-not-supported-for-lazyfr","errorCode":null,"errorMessage":"\"{operator!r}\" comparison not supported for LazyFrame objects","messagePattern":"\"(.+?)\" comparison not supported for LazyFrame objects","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/lazyframe/frame.py","lineNumber":727,"sourceCode":"        \"\"\"\n        issue_warning(\n            \"determining the width of a LazyFrame requires resolving its schema,\"\n            \" which is a potentially expensive operation. Use `LazyFrame.collect_schema().len()`\"\n            \" to get the width without this warning.\",\n            category=PerformanceWarning,\n        )\n        return self.collect_schema().len()\n\n    def __bool__(self) -> NoReturn:\n        msg = (\n            \"the truth value of a LazyFrame is ambiguous\"\n            \"\\n\\nLazyFrames cannot be used in boolean context with and/or/not operators.\"\n        )\n        raise TypeError(msg)\n\n    def _comparison_error(self, operator: str) -> NoReturn:\n        msg = f'\"{operator!r}\" comparison not supported for LazyFrame objects'\n        raise TypeError(msg)\n\n    def __eq__(self, other: object) -> NoReturn:\n        self._comparison_error(\"==\")\n\n    def __ne__(self, other: object) -> NoReturn:\n        self._comparison_error(\"!=\")\n\n    def __gt__(self, other: Any) -> NoReturn:\n        self._comparison_error(\">\")\n\n    def __lt__(self, other: Any) -> NoReturn:\n        self._comparison_error(\"<\")\n\n    def __ge__(self, other: Any) -> NoReturn:\n        self._comparison_error(\">=\")\n\n    def __le__(self, other: Any) -> NoReturn:\n        self._comparison_error(\"<=\")","sourceCodeStart":709,"sourceCodeEnd":745,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/lazyframe/frame.py#L709-L745","documentation":"LazyFrames are lazy/query objects, not row data, so Polars forbids element-wise comparison operators (==, !=, <, >, <=, >=) on them. All rich comparisons on LazyFrame raise this TypeError because comparing two query plans is undefined. Comparing a LazyFrame is almost always a mistake where the user meant to compare collected DataFrames or to build an expression inside select/filter.","triggerScenarios":"Any direct comparison: lf == other_lf, lf != x, lf > 5, sorting a list of LazyFrames, or using lf in a context that calls __eq__ (e.g. `lf in [lf1, lf2]`, set/dict usage, `assert lf == expected`).","commonSituations":"Unit tests asserting two lazy frames are equal; using a LazyFrame in an `in` check or as a dict key; code refactored from DataFrame to LazyFrame; accidentally comparing a LazyFrame to a DataFrame.","solutions":["Collect both sides and compare DataFrames: `lf.collect() == lf2.collect()`","If comparing plans, compare `lf.explain()` strings or serialized plans instead","For row logic, use expression comparisons inside `filter`/`select` (e.g. `lf.select(pl.col('a') == 1)`)","Replace `assert lf == x` in tests with `assert_frame_equal` from polars.testing"],"exampleFix":"// before\nassert lf == lf2\n\n// after\nfrom polars.testing import assert_frame_equal\nassert_frame_equal(lf.collect(), lf2.collect())","handlingStrategy":"type-guard","validationCode":"if isinstance(obj, pl.LazyFrame):\n    obj = obj.collect()  # materialize before comparing","typeGuard":"def is_lazyframe(obj) -> bool:\n    return isinstance(obj, pl.LazyFrame)","tryCatchPattern":"try:\n    result = lf == other\nexcept TypeError as e:\n    if \"comparison not supported for LazyFrame\" in str(e):\n        result = lf.collect() == other.collect()\n    else:\n        raise","preventionTips":["Check isinstance(x, pl.LazyFrame) before comparisons","Use polars.testing.assert_frame_equal on collected frames in tests","Never use LazyFrames as dict keys or in `in` checks"],"tags":["python","polars","lazyframe","type-error"],"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"}