{"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":300,"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":282,"sourceCodeEnd":306,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_utils/parse/expr.py#L282-L306","documentation":"_combine_predicates combines predicate PyExprs with all_horizontal. With zero predicates there is nothing to AND, and an empty filter would be ambiguous, so a TypeError is raised demanding at least one predicate or constraint.","triggerScenarios":"Calling parse_predicates_constraints_into_expression / filter-style APIs (df.filter(), LazyFrame.filter, delete/update constraints) with no arguments or with only all-falsy inputs that yield no predicates, e.g. df.filter() or df.filter(**empty_dict).","commonSituations":"Programmatically building filters from a dict/list that turned out empty, or user input contributing zero conditions.","solutions":["Provide at least one predicate: df.filter(pl.col(\"a\") > 1).","Guard before calling: if conditions: df.filter(*conditions).","Use pl.lit(True) as a neutral predicate when an empty filter must be represented: df.filter(pl.lit(True)).","When building from kwargs, ensure the dict is non-empty or fall back to no filtering."],"exampleFix":"// before\ndf.filter(**conditions)  # conditions may be {}\n// after\nif conditions:\n    df = df.filter(**conditions)\nelse:\n    df = df.filter(pl.lit(True))","handlingStrategy":"validation","validationCode":"def require_predicates(predicates):\n    if not predicates:\n        raise ValueError(\"filter requires at least one predicate\")\n    return predicates","typeGuard":null,"tryCatchPattern":"try:\n    result = df.filter(*predicates)\nexcept TypeError as e:\n    if \"at least one predicate\" in str(e):\n        result = df.filter(pl.lit(True))\n    else:\n        raise","preventionTips":["Guard dynamic filter building with `if conditions:` before calling.","Document that zero-condition filters must short-circuit to no-op.","Use pl.lit(True) as an identity predicate when combining programmatically.","Unit-test filter builders with empty-input cases."],"tags":["polars","filter","predicates"],"backgroundTag":"missing-required-argument","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"}