{"record":{"id":"78c6df7b7ea1e3a3","repo":"pola-rs/polars","slug":"unknown-comparison-op","errorCode":null,"errorMessage":"Unknown comparison: {op}","messagePattern":"Unknown comparison: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/iceberg/_utils.py","lineNumber":323,"sourceCode":"@_convert_predicate.register(Compare)\ndef _(a: Compare) -> Any:\n    op = a.ops[0]\n    lhs = _convert_predicate(a.left)[0]\n    rhs = _convert_predicate(a.comparators[0])\n\n    if isinstance(op, Gt):\n        return pyiceberg.expressions.GreaterThan(lhs, rhs)  # type: ignore[misc, call-arg]\n    if isinstance(op, GtE):\n        return pyiceberg.expressions.GreaterThanOrEqual(lhs, rhs)  # type: ignore[misc, call-arg]\n    if isinstance(op, Eq):\n        return pyiceberg.expressions.EqualTo(lhs, rhs)  # type: ignore[misc, call-arg]\n    if isinstance(op, Lt):\n        return pyiceberg.expressions.LessThan(lhs, rhs)  # type: ignore[misc, call-arg]\n    if isinstance(op, LtE):\n        return pyiceberg.expressions.LessThanOrEqual(lhs, rhs)  # type: ignore[misc, call-arg]\n    else:\n        msg = f\"Unknown comparison: {op}\"\n        raise TypeError(msg)\n\n\n@_convert_predicate.register(List)\ndef _(a: List) -> Any:\n    return [_convert_predicate(e) for e in a.elts]\n\n\ndef extract_field_initial_default(field: NestedField) -> pl.Series | None:\n    from pyiceberg.types import (\n        UUIDType,\n    )\n\n    if field.initial_default is None:\n        return None\n\n    value = field.initial_default\n\n    if isinstance(field.field_type, UUIDType):","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/iceberg/_utils.py#L305-L341","documentation":"Compare nodes in the pyarrow predicate AST are translated to pyiceberg comparisons; the handler covers Lt, LtE (and sibling ops earlier in the chain: Gt, GtE, Eq, NotEq). A comparison operator outside the mapped set reaches the fallback and raises TypeError('Unknown comparison: {op}').","triggerScenarios":"A pyarrow.compute filter with a comparison operator the converter doesn't map — e.g. `pc.field('a') % 2 == 0` producing non-compare nodes is handled elsewhere, but operators like `In` via compare, chained comparisons (`a < b < c` producing multiple ops), or an exotic op reaching this branch with an unmapped ast.cmpop.","commonSituations":"Chained Python comparisons in filters; using operators like `is`/`in` through the compare path; polars/pyarrow version drift where an op isn't in the mapping.","solutions":["Use single, explicit comparisons: ==, !=, <, <=, >, >=, and pc/field is_null/is_nan calls","Split chained comparisons into separate &-combined predicates","For membership tests use pyiceberg's In expression or an equivalent `|`-chain of equality checks","Upgrade polars if the operator is newly supported upstream"],"exampleFix":"// before\npc.field('a') < pc.field('b') < pc.field('c')  # chained compare\n// after\n(pc.field('a') < pc.field('b')) & (pc.field('b') < pc.field('c'))","handlingStrategy":"validation","validationCode":"def comparisons_supported(expr) -> bool:\n    import ast\n    ok = {ast.Lt, ast.LtE, ast.Gt, ast.GtE, ast.Eq, ast.NotEq}\n    return all(isinstance(n.ops[0], ok) for n in ast.walk(expr) if isinstance(n, ast.Compare))","typeGuard":null,"tryCatchPattern":"try:\n    lf = pl.scan_iceberg(src, filter=pred)\nexcept TypeError as e:\n    if 'Unknown comparison' in str(e):\n        lf = pl.scan_iceberg(src).filter(downstream_condition)","preventionTips":["Use one explicit comparison per sub-predicate; avoid chained comparisons (a < b < c)","Stick to ==, !=, <, <=, >, >= in pushdown filters","Express membership as OR of equality or a pyiceberg In expression","Validate filters in tests before deploying scan jobs"],"tags":["iceberg","predicate","pyarrow","comparison-operator"],"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"}