{"record":{"id":"00215b1f9feb1b0a","repo":"pola-rs/polars","slug":"at-least-one-predicate-or-constraint-must-be-provi-00215b","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/lazyframe/frame.py","lineNumber":4707,"sourceCode":"                err = (\n                    f\"Series(…, dtype={p.dtype})\"\n                    if isinstance(p, pl.Series)\n                    else repr(p)\n                )\n                msg = f\"invalid predicate for `filter`: {err}\"\n                raise TypeError(msg)\n            else:\n                all_predicates.extend(\n                    wrap_expr(x) for x in parse_into_list_of_expressions(p)\n                )\n\n        # unpack equality constraints from kwargs\n        all_predicates.extend(\n            F.col(name).eq(value) for name, value in constraints.items()\n        )\n        if not (all_predicates or boolean_masks):\n            msg = \"at least one predicate or constraint must be provided\"\n            raise TypeError(msg)\n\n        # if multiple predicates, combine as 'horizontal' expression\n        combined_predicate = (\n            (\n                F.all_horizontal(*all_predicates)\n                if len(all_predicates) > 1\n                else all_predicates[0]\n            )\n            if all_predicates\n            else None\n        )\n\n        # apply reduced boolean mask first, if applicable, then predicates\n        if boolean_masks:\n            mask_expr = F.lit(reduce(and_, boolean_masks))\n            combined_predicate = (\n                mask_expr\n                if combined_predicate is None","sourceCodeStart":4689,"sourceCodeEnd":4725,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/lazyframe/frame.py#L4689-L4725","documentation":"LazyFrame.filter() raises TypeError when it ends up with no predicates at all — no positional predicates, no keyword equality constraints, and no boolean masks. This typically happens when predicates are built dynamically and the list comes back empty, rather than from an explicit literal call.","triggerScenarios":"predicates = [p for p in candidates if p]; lf.filter(*predicates) with an empty result; lf.filter() called with no args inside a generic pipeline; all predicates filtered out by a condition.","commonSituations":"Config-driven filtering where no filter rules are enabled; data pipelines that apply filters conditionally; refactors that leave a bare filter() call.","solutions":["Skip the filter call when the predicate list is empty: lf = lf.filter(*preds) if preds else lf","Supply at least one predicate or a keyword constraint (lf.filter(col=val))","Default to an always-true expression if a no-op filter is intended: lf.filter(pl.lit(True))"],"exampleFix":"# before\npreds = build_predicates(cfg)  # may be []\nlf = lf.filter(*preds)\n\n# after\npreds = build_predicates(cfg)\nif preds:\n    lf = lf.filter(*preds)","handlingStrategy":"validation","validationCode":"if not preds and not constraints:\n    lf_result = lf  # no-op instead of error\nelse:\n    lf_result = lf.filter(*preds, **constraints)","typeGuard":"def has_any_predicate(preds, constraints) -> bool:\n    return bool(preds) or bool(constraints)","tryCatchPattern":null,"preventionTips":["Guard dynamic filter construction with an emptiness check","Default config-driven filter lists to at least one trivially-true rule if a no-op is desired"],"tags":["polars","lazyframe","filter","empty-arguments"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}