{"record":{"id":"6214ccee128fdfad","repo":"pola-rs/polars","slug":"at-least-one-predicate-or-constraint-must-be-provi","errorCode":null,"errorMessage":"at least one predicate or constraint must be provided","messagePattern":"at least one predicate or constraint must be provided","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/parse/expr.py","lineNumber":304,"sourceCode":"    \"\"\"\n    all_predicates = _parse_positional_inputs(predicates)  # type: ignore[arg-type]\n\n    if constraints:\n        constraint_predicates = _parse_constraints(constraints)\n        all_predicates.extend(constraint_predicates)\n\n    return _combine_predicates(all_predicates)\n\n\ndef _parse_constraints(constraints: dict[str, IntoExpr]) -> Iterable[PyExpr]:\n    for name, value in constraints.items():\n        yield F.col(name).eq(value)._pyexpr\n\n\ndef _combine_predicates(predicates: list[PyExpr]) -> PyExpr:\n    if not predicates:\n        msg = \"at least one predicate or constraint must be provided\"\n        raise TypeError(msg)\n\n    if len(predicates) == 1:\n        return predicates[0]\n\n    return plr.all_horizontal(predicates)\n","sourceCodeStart":286,"sourceCodeEnd":310,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/_utils/parse/expr.py#L286-L310","documentation":"_combine_predicates (parse/expr.py:304) requires at least one predicate across the *predicates and **constraints accepted by pl.when(...), Expr.when(...), and Expr.filter(...). With zero inputs there is nothing to AND together, so it raises this TypeError rather than producing a meaningless expression that would fail later.","triggerScenarios":"pl.when() called with no arguments; dynamically assembled predicate lists that end up empty: pl.when(*preds) with preds == []; expr.filter() with no predicates; when(**constraints) with an empty dict.","commonSituations":"Config/user-driven predicate builders; helper functions forwarding *args into when()/filter(); branches where all optional filters are absent.","solutions":["Default to a neutral predicate: preds = predicates or [pl.lit(True)] before pl.when(*preds)","Skip the when/otherwise chain entirely when no predicates apply","Validate at the API boundary: require at least one predicate or constraint"],"exampleFix":"# before\npl.when(*predicates).then(x).otherwise(y)  # predicates == []\n\n# after\npredicates = predicates or [pl.lit(True)]\npl.when(*predicates).then(x).otherwise(y)","handlingStrategy":"validation","validationCode":"if not predicates and not constraints:\n    raise TypeError(\"at least one predicate or constraint must be provided\")\npl.when(*predicates, **constraints)","typeGuard":"def has_any_predicate(predicates, constraints) -> bool:\n    return len(predicates) > 0 or len(constraints) > 0","tryCatchPattern":null,"preventionTips":["Default empty predicate lists to [pl.lit(True)] when a when-chain is still required","Validate user-supplied filter lists before forwarding to when/filter","Consider skipping the when/otherwise branch entirely when nothing applies"],"tags":["python","polars","when-then","filter","predicates","typeerror"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}