{"record":{"id":"04e2f075751186a2","repo":"pola-rs/polars","slug":"func-name-r-received-both-old-name-r-and","errorCode":null,"errorMessage":"`{func_name!r}` received both `{old_name!r}` and `{new_name!r}` as arguments; `{old_name!r}` {is_deprecated}, use `{new_name!r}` instead","messagePattern":"`(.+?)` received both `(.+?)` and `(.+?)` as arguments; `(.+?)` (.+?), use `(.+?)` instead","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/_utils/deprecation.py","lineNumber":131,"sourceCode":"\ndef _rename_keyword_argument(\n    old_name: str,\n    new_name: str,\n    kwargs: dict[str, object],\n    func_name: str,\n    version: str,\n) -> None:\n    \"\"\"Rename a keyword argument of a function.\"\"\"\n    if old_name in kwargs:\n        if new_name in kwargs:\n            is_deprecated = (\n                f\"was deprecated in version {version}\" if version else \"is deprecated\"\n            )\n            msg = (\n                f\"`{func_name!r}` received both `{old_name!r}` and `{new_name!r}` as arguments;\"\n                f\" `{old_name!r}` {is_deprecated}, use `{new_name!r}` instead\"\n            )\n            raise TypeError(msg)\n\n        in_version = f\" in version {version}\" if version else \"\"\n        issue_deprecation_warning(\n            f\"the argument `{old_name}` for `{func_name}` is deprecated. \"\n            f\"It was renamed to `{new_name}`{in_version}.\"\n        )\n        kwargs[new_name] = kwargs.pop(old_name)\n\n\ndef deprecate_nonkeyword_arguments(\n    allowed_args: list[str] | None = None, message: str | None = None, *, version: str\n) -> IdentityFunction:\n    \"\"\"\n    Decorator for deprecating the use of non-keyword arguments in a function.\n\n    Use as follows:\n\n        @deprecate_nonkeyword_arguments(allowed_args=[\"self\", \"val\"], version=\"1.0.0\")","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/_utils/deprecation.py#L113-L149","documentation":"Polars raises this TypeError when a decorated (deprecated-renamed) function receives both the old keyword argument name and the new one. The `_rename_keyword_argument` wrapper detects the conflict and hard-fails instead of guessing which value to use.","triggerScenarios":"Calling a function that had a keyword renamed (e.g. `fmt` -> `format`) while still passing the old name alongside the new one, such as `func(df, fmt='x', format='y')`.","commonSituations":"Partially completed migration after a Polars version upgrade; a wrapper layer that forwards both old and new kwargs; copying old example code into new code that already uses the new name.","solutions":["Remove the deprecated old-name argument and keep only the new name","Update all call sites/wrappers to forward only the new keyword","Pin or align the Polars version if a dependency still passes the old kwarg"],"exampleFix":"// before\nseries.upsample(fmt=\"time_column\", every=\"1h\", time_column=\"ts\")\n// after\nseries.upsample(every=\"1h\", time_column=\"ts\")","handlingStrategy":"try-catch","validationCode":"if old_name in kwargs and new_name in kwargs:\n    kwargs.pop(old_name)  # prefer new name before calling","typeGuard":null,"tryCatchPattern":"try:\n    result = func(df, **kwargs)\nexcept TypeError as e:\n    if \"received both\" in str(e):\n        kwargs.pop(old_name, None)\n        result = func(df, **kwargs)\n    else:\n        raise","preventionTips":["After upgrading Polars, replace all old kwarg names at call sites (search-and-replace)","Never forward both old and new kwargs from wrapper layers","Read the deprecation warnings emitted before the removal release"],"tags":["python","polars","deprecated-api","keyword-arguments"],"backgroundTag":"deprecated-api-usage","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"}