pola-rs/polars · error

'join_where' requires at least one predicate

Error message

'join_where' requires at least one predicate

What it means

Raised by `resolve_join_where` in crates/polars-plan/src/plans/conversion/dsl_to_ir/join.rs when an equi-join_on join_where conversion ends up with zero predicates to AND together. The optimizer expects at least one predicate node in the expression arena; an empty list is an internal invariant violation.

Solutions

  1. Pass at least one predicate expression to join_where
  2. Guard the caller: if the predicate list is empty, fall back to a plain cross join + filter or raise a clear error
  3. Update polars if a version-specific bug dropped valid predicates before this check

Example fix

// before
lf.join_where(other, [])  // empty predicates
// after
assert predicates, "join_where requires at least one predicate"
lf.join_where(other, predicates)
Defensive patterns

Strategy: validation

Validate before calling

if not predicates:
    raise ValueError("join_where requires at least one predicate")
result = lf.join_where(other, predicates)

Type guard

def has_predicates(preds: list) -> bool:
    return len(preds) > 0

Try / catch

try:
    result = lf.join_where(other, predicates).collect()
except pl.exceptions.PanicException as e:
    if "at least one predicate" in str(e):
        result = lf.join(other, how="cross").filter(default_predicate).collect()
    else:
        raise

Prevention

When it happens

Trigger: Calling `join_where()` with an empty predicate list / no predicate expressions, so the fold over predicates produces nothing and `.expect("'join_where' requires at least one predicate")` fires.

Common situations: Programmatically building join_where predicates from a filtered list that turned out empty (e.g. predicates removed by dead-code or column filtering), or calling join_where with no args.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at crates/polars-plan/src/plans/conversion/dsl_to_ir/join.rs:600

            last_node = ctxt.lp_arena.add(ir);
        }
    } else {
        // For left and right joins, we cannot lower to cross + filters
        // as null outputs for missing rows would not be preserved.
        // We attach the join predicates/conditions to the joins itself
        // and restore the original `how` join type.
        let node = resolved
            .iter()
            .map(|e| e.node())
            .reduce(|left, right| {
                ctxt.expr_arena.add(AExpr::BinaryExpr {
                    left,
                    op: Operator::And,
                    right,
                })
            })
            .expect("'join_where' requires at least one predicate");
        let predicate = ExprIR::from_node(node, ctxt.expr_arena);

        let IR::Join { options, .. } = ctxt.lp_arena.get(join_node) else {
            unreachable!()
        };
        let mut new_options = (**options).clone();
        new_options.args.how = how;
        new_options.options = JoinTypeOptionsIR::CrossAndFilter { predicate };

        let IR::Join { options, .. } = ctxt.lp_arena.get_mut(join_node) else {
            unreachable!()
        };
        *options = Arc::new(new_options);
    }

    ctxt.conversion_optimizer
        .optimize_exprs(ctxt.expr_arena, ctxt.lp_arena, last_node, false)
        .context("'join_where' failed")?;

View on GitHub (pinned to fe841f959e)