{"record":{"id":"1bd8eef33242889d","repo":"pola-rs/polars","slug":"join-where-requires-at-least-one-predicate","errorCode":null,"errorMessage":"'join_where' requires at least one predicate","messagePattern":"'join_where' requires at least one predicate","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-plan/src/plans/conversion/dsl_to_ir/join.rs","lineNumber":600,"sourceCode":"\n            last_node = ctxt.lp_arena.add(ir);\n        }\n    } else {\n        // For left and right joins, we cannot lower to cross + filters\n        // as null outputs for missing rows would not be preserved.\n        // We attach the join predicates/conditions to the joins itself\n        // and restore the original `how` join type.\n        let node = resolved\n            .iter()\n            .map(|e| e.node())\n            .reduce(|left, right| {\n                ctxt.expr_arena.add(AExpr::BinaryExpr {\n                    left,\n                    op: Operator::And,\n                    right,\n                })\n            })\n            .expect(\"'join_where' requires at least one predicate\");\n        let predicate = ExprIR::from_node(node, ctxt.expr_arena);\n\n        let IR::Join { options, .. } = ctxt.lp_arena.get(join_node) else {\n            unreachable!()\n        };\n        let mut new_options = (**options).clone();\n        new_options.args.how = how;\n        new_options.options = JoinTypeOptionsIR::CrossAndFilter { predicate };\n\n        let IR::Join { options, .. } = ctxt.lp_arena.get_mut(join_node) else {\n            unreachable!()\n        };\n        *options = Arc::new(new_options);\n    }\n\n    ctxt.conversion_optimizer\n        .optimize_exprs(ctxt.expr_arena, ctxt.lp_arena, last_node, false)\n        .context(\"'join_where' failed\")?;","sourceCodeStart":582,"sourceCodeEnd":618,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-plan/src/plans/conversion/dsl_to_ir/join.rs#L582-L618","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass at least one predicate expression to join_where","Guard the caller: if the predicate list is empty, fall back to a plain cross join + filter or raise a clear error","Update polars if a version-specific bug dropped valid predicates before this check"],"exampleFix":"// before\nlf.join_where(other, [])  // empty predicates\n// after\nassert predicates, \"join_where requires at least one predicate\"\nlf.join_where(other, predicates)","handlingStrategy":"validation","validationCode":"if not predicates:\n    raise ValueError(\"join_where requires at least one predicate\")\nresult = lf.join_where(other, predicates)","typeGuard":"def has_predicates(preds: list) -> bool:\n    return len(preds) > 0","tryCatchPattern":"try:\n    result = lf.join_where(other, predicates).collect()\nexcept pl.exceptions.PanicException as e:\n    if \"at least one predicate\" in str(e):\n        result = lf.join(other, how=\"cross\").filter(default_predicate).collect()\n    else:\n        raise","preventionTips":["Never build join_where predicate lists by silent filtering; assert non-empty first","Fail fast in pipeline builders when predicate construction yields nothing","Prefer raising a clear Python error over an empty predicate list"],"tags":["rust","join","empty-argument","panic"],"backgroundTag":"empty-required-field","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"}