pola-rs/polars · error · TypeError

Unknown

Error message

Unknown: {lhs} {op} {rhs}

What it means

Boolean combination nodes in the pyarrow predicate AST (BinOp) are supported only for BitAnd (`&`) and BitOr (`|`), mapping to pyiceberg And/Or. Any other binary operator (arithmetic +,-,*, /, shifts, etc.) reaches the fallback and raises TypeError('Unknown: lhs op rhs').

Solutions

  1. Combine conditions with `&` and `|` only, parenthesizing each comparison
  2. Move arithmetic out of the filter (precompute or filter after load with polars)
  3. Express the predicate as a pyiceberg expression directly for shapes pyarrow filters can't represent

Example fix

// before
pc.field('a') + pc.field('b') == 3  # Unknown: ...
// after
(pc.field('a') == 1) & (pc.field('b') == 2)
Defensive patterns

Strategy: validation

Validate before calling

def boolean_ops_ok(expr) -> bool:
    import ast
    return all(isinstance(n.op, (ast.BitAnd, ast.BitOr))
               for n in ast.walk(expr) if isinstance(n, ast.BinOp))

Try / catch

try:
    lf = pl.scan_iceberg(src, filter=pred)
except TypeError as e:
    if 'Unknown:' in str(e):
        lf = pl.scan_iceberg(src).filter(downstream_condition)

Prevention

When it happens

Trigger: A pyarrow.compute filter passed to scan_iceberg combining operands with operators other than `&`/`|` — e.g. `pc.field('a') + pc.field('b') == 3`, or using `and`/`or` keywords that leaked into the AST, or XOR-like constructs.

Common situations: Writing SQL-style `and`/`or` instead of `&`/`|` in pyarrow expressions; doing arithmetic inside filters; mixing bitwise ops with comparisons in ways the AST walker can't lower to Iceberg predicates.

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/42083c47bb27673c. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/io/iceberg/_utils.py:302

@_convert_predicate.register(Attribute)
def _(a: Attribute) -> Any:
    return a.attr


@_convert_predicate.register(BinOp)
def _(a: BinOp) -> Any:
    lhs = _ensure_boolean_expression(_convert_predicate(a.left))
    rhs = _ensure_boolean_expression(_convert_predicate(a.right))

    op = a.op
    if isinstance(op, BitAnd):
        return pyiceberg.expressions.And(lhs, rhs)
    if isinstance(op, BitOr):
        return pyiceberg.expressions.Or(lhs, rhs)
    else:
        msg = f"Unknown: {lhs} {op} {rhs}"
        raise TypeError(msg)


@_convert_predicate.register(Compare)
def _(a: Compare) -> Any:
    op = a.ops[0]
    lhs = _convert_predicate(a.left)[0]
    rhs = _convert_predicate(a.comparators[0])

    if isinstance(op, Gt):
        return pyiceberg.expressions.GreaterThan(lhs, rhs)  # type: ignore[misc, call-arg]
    if isinstance(op, GtE):
        return pyiceberg.expressions.GreaterThanOrEqual(lhs, rhs)  # type: ignore[misc, call-arg]
    if isinstance(op, Eq):
        return pyiceberg.expressions.EqualTo(lhs, rhs)  # type: ignore[misc, call-arg]
    if isinstance(op, Lt):
        return pyiceberg.expressions.LessThan(lhs, rhs)  # type: ignore[misc, call-arg]
    if isinstance(op, LtE):
        return pyiceberg.expressions.LessThanOrEqual(lhs, rhs)  # type: ignore[misc, call-arg]

View on GitHub (pinned to fe841f959e)