{"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":2220,"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":2202,"sourceCodeEnd":2238,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/lazyframe/frame.py#L2202-L2238","documentation":"The engine-based collect() validates its keyword arguments and raises TypeError for any kwarg it does not recognize (except the internal 'post_opt_callback'). This usually means an argument valid for an older collect() signature (or another method) was passed here.","triggerScenarios":"`lf.collect(streaming=True)` on new polars, passing old flags like `type_coercion=False` directly, or forwarding wrapper **kwargs into collect().","commonSituations":"Upgrading polars where parameters moved into `engine`/`optimizations`; wrappers that blindly pass **kwargs; copying collect_all or scan options into collect.","solutions":["Remove the unknown kwarg and consult the current collect() signature","Migrate `streaming=True` to `engine='streaming'`","Pass plan optimizations via the `optimizations=` parameter instead of individual flags"],"exampleFix":"// before\ndf = lf.collect(streaming=True)\n\n// after\ndf = lf.collect(engine='streaming')","handlingStrategy":"validation","validationCode":"import inspect\nvalid = inspect.signature(lf.collect).parameters\nunexpected = set(kwargs) - set(valid)\nassert not unexpected, f\"unexpected kwargs: {unexpected}\"","typeGuard":null,"tryCatchPattern":"try:\n    df = lf.collect(**kwargs)\nexcept TypeError as e:\n    if \"unexpected keyword argument\" in str(e):\n        kwargs.pop('streaming', None)\n        df = lf.collect(engine='streaming', **kwargs)\n    else:\n        raise","preventionTips":["Verify collect()'s signature for your polars version (inspect.signature)","Migrate deprecated flags (streaming=) to engine=/optimizations=","Filter **kwargs in wrappers before forwarding to collect()"],"tags":["python","polars","api-change","keyword-arguments"],"backgroundTag":"invalid-query-parameter","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"}