{"record":{"id":"148d3a72d6833e05","repo":"pola-rs/polars","slug":"collect-got-an-unexpected-keyword-argument-k","errorCode":null,"errorMessage":"collect() got an unexpected keyword argument '{k}'","messagePattern":"collect\\(\\) got an unexpected keyword argument '(.+?)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/lazyframe/frame.py","lineNumber":2584,"sourceCode":"        ...     engine=pl.GPUEngine(device=1)\n        ... )  # doctest: +SKIP\n        shape: (3, 3)\n        ┌─────┬─────┬─────┐\n        │ a   ┆ b   ┆ c   │\n        │ --- ┆ --- ┆ --- │\n        │ str ┆ i64 ┆ i64 │\n        ╞═════╪═════╪═════╡\n        │ b   ┆ 11  ┆ 10  │\n        │ a   ┆ 4   ┆ 10  │\n        │ c   ┆ 6   ┆ 1   │\n        └─────┴─────┴─────┘\n        \"\"\"\n        for k in _kwargs:\n            if k not in (  # except \"private\" kwargs\n                \"post_opt_callback\",\n            ):\n                error_msg = f\"collect() got an unexpected keyword argument '{k}'\"\n                raise TypeError(error_msg)\n\n        engine_ = _select_engine(engine)\n        post_opt_callback = _kwargs.get(\"post_opt_callback\")\n\n        return engine_.collect(\n            self,\n            optimizations=optimizations,\n            background=background,\n            post_opt_callback=post_opt_callback,\n        )\n\n    @overload\n    def collect_async(\n        self,\n        *,\n        gevent: Literal[True],\n        engine: EngineType = \"auto\",\n        optimizations: QueryOptFlags = DEFAULT_QUERY_OPT_FLAGS,","sourceCodeStart":2566,"sourceCodeEnd":2602,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/lazyframe/frame.py#L2566-L2602","documentation":"LazyFrame.collect() explicitly rejects any **kwargs except the private post_opt_callback. Parameters like engine, optimizations, and background are named parameters and must be passed as such; anything else routed through **kwargs raises TypeError. This guard was added to catch silently-ignored typos and removed parameters (e.g. the old no_optimization kwarg).","triggerScenarios":"lf.collect(no_optimization=True) (removed parameter), lf.collect(streaming=True) (removed in favor of engine), or lf.collect(**user_options) where user_options contains stale keys. Refactoring code from polars <1.0 to current versions.","commonSituations":"Version upgrades from polars 0.20/1.x where collect(streaming=True) or no_optimization were valid; generic option dicts shared across APIs.","solutions":["Replace collect(streaming=True) with collect(engine='streaming')","Replace no_optimization=True with optimizations=Optimizations.none() (named arg)","Filter forwarded **options dicts to the known parameter names before calling collect","Run python -c 'import inspect; print(inspect.signature(lf.collect))' after upgrade to see the current signature"],"exampleFix":"# before\nlf.collect(streaming=True)\n\n# after\nlf.collect(engine='streaming')","handlingStrategy":"validation","validationCode":"import inspect\nsig = inspect.signature(lf.collect)\nkwargs = {k: v for k, v in kwargs.items() if k in sig.parameters}\ndf = lf.collect(**kwargs)","typeGuard":"def is_collect_parameter(k: str) -> bool:\n    import inspect\n    return k in inspect.signature(lf.collect).parameters","tryCatchPattern":"try:\n    df = lf.collect(**opts)\nexcept TypeError as e:\n    if 'unexpected keyword' in str(e):\n        raise ValueError(f'invalid collect options: {opts}') from e\n    raise","preventionTips":["Replace removed kwargs (streaming, no_optimization) with engine/optimizations","Keep an explicit list of allowed collect options and filter **kwargs against it","Add a smoke test that calls collect with your production options dict"],"tags":["polars","lazyframe","collect","kwargs","version-migration"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}