pola-rs/polars · error · TypeError
at least one predicate or constraint must be provided
Error message
at least one predicate or constraint must be provided
What it means
_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.
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.
Example fix
// before
df.filter(**conditions) # conditions may be {}
// after
if conditions:
df = df.filter(**conditions)
else:
df = df.filter(pl.lit(True)) Defensive patterns
Strategy: validation
Validate before calling
def require_predicates(predicates):
if not predicates:
raise ValueError("filter requires at least one predicate")
return predicates Try / catch
try:
result = df.filter(*predicates)
except TypeError as e:
if "at least one predicate" in str(e):
result = df.filter(pl.lit(True))
else:
raise Prevention
- 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.
When it happens
Trigger: 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).
Common situations: Programmatically building filters from a dict/list that turned out empty, or user input contributing zero conditions.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- at least one predicate or constraint must be provided
- invalid predicate for `filter
- selecting rows by passing a boolean mask to `__getitem__`…
- {0}
- a more recent version of `fastexcel` is required for…
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/6214ccee128fdfad.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/_utils/parse/expr.py:300
"""
all_predicates = _parse_positional_inputs(predicates) # type: ignore[arg-type]
if constraints:
constraint_predicates = _parse_constraints(constraints)
all_predicates.extend(constraint_predicates)
return _combine_predicates(all_predicates)
def _parse_constraints(constraints: dict[str, IntoExpr]) -> Iterable[PyExpr]:
for name, value in constraints.items():
yield F.col(name).eq(value)._pyexpr
def _combine_predicates(predicates: list[PyExpr]) -> PyExpr:
if not predicates:
msg = "at least one predicate or constraint must be provided"
raise TypeError(msg)
if len(predicates) == 1:
return predicates[0]
return plr.all_horizontal(predicates)
View on GitHub (pinned to fe841f959e)