{"record":{"id":"ee1f40b2d6306942","repo":"pola-rs/polars","slug":"profile-got-an-unexpected-keyword-argument-k","errorCode":null,"errorMessage":"profile() got an unexpected keyword argument '{k}'","messagePattern":"profile\\(\\) got an unexpected keyword argument '(.+?)'","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/lazyframe/frame.py","lineNumber":2179,"sourceCode":"         │ c   ┆ 6   ┆ 1   │\n         └─────┴─────┴─────┘,\n         shape: (3, 3)\n         ┌─────────────────────────┬───────┬──────┐\n         │ node                    ┆ start ┆ end  │\n         │ ---                     ┆ ---   ┆ ---  │\n         │ str                     ┆ u64   ┆ u64  │\n         ╞═════════════════════════╪═══════╪══════╡\n         │ optimization            ┆ 0     ┆ 5    │\n         │ group_by_partitioned(a) ┆ 5     ┆ 470  │\n         │ sort(a)                 ┆ 475   ┆ 1964 │\n         └─────────────────────────┴───────┴──────┘)\n        \"\"\"\n        for k in _kwargs:\n            if k not in (  # except \"private\" kwargs\n                \"post_opt_callback\",\n            ):\n                error_msg = f\"profile() got an unexpected keyword argument '{k}'\"\n                raise TypeError(error_msg)\n        engine = _select_engine(engine)\n\n        optimizations = optimizations.__copy__()\n        ldf = self._ldf.with_optimizations(optimizations._pyoptflags)\n\n        callback = (\n            engine._post_opt_callback(background=False, eager=False)\n            if isinstance(engine, GPUEngine)\n            else None\n        )\n        if _kwargs.get(\"post_opt_callback\") is not None:\n            callback = _kwargs.get(\"post_opt_callback\")\n        df_py, timings_py = ldf.profile(callback)\n        (df, timings) = wrap_df(df_py), wrap_df(timings_py)\n\n        if show_plot:\n            import_optional(\n                \"matplotlib\",","sourceCodeStart":2161,"sourceCodeEnd":2197,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/lazyframe/frame.py#L2161-L2197","documentation":"LazyFrame.profile() no longer accepts arbitrary **kwargs; the only 'private' kwarg still honored is post_opt_callback. Anything else (e.g. the old engine/optimizations-style keywords or deprecated aliases like collect-related args) raises TypeError. This mirrors the same guard on collect().","triggerScenarios":"Calling lf.profile(engine='streaming') or lf.profile(no_optimization=True) — kwargs that older polars versions accepted or that belong to collect()'s named parameters. Passing leftovers from **options dicts built for other calls.","commonSituations":"Upgrading polars across versions where collect/profile kwargs were cleaned up; forwarding a shared **options dict to multiple frame methods.","solutions":["Remove the invalid kwarg; pass supported options as named parameters (engine=..., optimizations=...) instead of via **kwargs","If forwarding a dict, filter it to known keys first","Keep only post_opt_callback inside **kwargs","Check the current signature with help(lf.profile) after upgrading polars"],"exampleFix":"# before\nlf.profile(optimizations='none')  # wrong: goes into **_kwargs\n\n# after\nfrom polars.optimizer import Optimizations\nlf.profile(optimizations=Optimizations.none())","handlingStrategy":"validation","validationCode":"allowed = {'post_opt_callback'}\nextra = {k: v for k, v in kwargs.items() if k in allowed}\nlf.profile(**extra, engine=engine)","typeGuard":"def is_supported_profile_kwarg(k: str) -> bool:\n    return k == 'post_opt_callback'","tryCatchPattern":null,"preventionTips":["Never forward unfiltered **options dicts into profile/collect","Pin named parameters explicitly after upgrading polars","Check inspect.signature after major version bumps"],"tags":["polars","lazyframe","profile","kwargs","api-migration"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}