pola-rs/polars · error
` ` received both ` ` and ` ` as arguments; ` ` , use ` `…
Error message
`{func_name!r}` received both `{old_name!r}` and `{new_name!r}` as arguments; `{old_name!r}` {is_deprecated}, use `{new_name!r}` instead What it means
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.
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
Example fix
// before series.upsample(fmt="time_column", every="1h", time_column="ts") // after series.upsample(every="1h", time_column="ts")
Defensive patterns
Strategy: try-catch
Validate before calling
if old_name in kwargs and new_name in kwargs:
kwargs.pop(old_name) # prefer new name before calling Try / catch
try:
result = func(df, **kwargs)
except TypeError as e:
if "received both" in str(e):
kwargs.pop(old_name, None)
result = func(df, **kwargs)
else:
raise Prevention
- 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
When it happens
Trigger: 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')`.
Common situations: 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.
Understand the failure class
Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.
Related errors
- collect() got an unexpected keyword argument
- received both and as arguments; has been renamed to in…
- accessing ` ` from the top-level `polars` module was…
- altair>=5.4.0 is required for `.plot`
- `arctan2` expected a `str` or `Expr` got a
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/04e2f075751186a2.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/_utils/deprecation.py:131
def _rename_keyword_argument(
old_name: str,
new_name: str,
kwargs: dict[str, object],
func_name: str,
version: str,
) -> None:
"""Rename a keyword argument of a function."""
if old_name in kwargs:
if new_name in kwargs:
is_deprecated = (
f"was deprecated in version {version}" if version else "is deprecated"
)
msg = (
f"`{func_name!r}` received both `{old_name!r}` and `{new_name!r}` as arguments;"
f" `{old_name!r}` {is_deprecated}, use `{new_name!r}` instead"
)
raise TypeError(msg)
in_version = f" in version {version}" if version else ""
issue_deprecation_warning(
f"the argument `{old_name}` for `{func_name}` is deprecated. "
f"It was renamed to `{new_name}`{in_version}."
)
kwargs[new_name] = kwargs.pop(old_name)
def deprecate_nonkeyword_arguments(
allowed_args: list[str] | None = None, message: str | None = None, *, version: str
) -> IdentityFunction:
"""
Decorator for deprecating the use of non-keyword arguments in a function.
Use as follows:
@deprecate_nonkeyword_arguments(allowed_args=["self", "val"], version="1.0.0")View on GitHub (pinned to fe841f959e)