pola-rs/polars · error · ArgumentRemovedError
received both and as arguments; has been renamed to in…
Error message
{func_name!r} received both {param.name!r} and {param.new_name!r} as arguments; {param.name!r}{was_deprecated_and} has been renamed to {param.new_name!r} in version {param.removed_in}. What it means
When a function decorated with `removed_parameters` receives both the removed (old) parameter name and its renamed replacement as keyword arguments, Polars raises ArgumentRemovedError immediately instead of guessing which value applies.
Solutions
- Pass only the new parameter name
- Remove the old-name kwarg from all call sites and wrappers
- Ensure library code no longer injects the new name as a default when forwarding legacy kwargs
Example fix
// before pl.read_csv(f, row_count_name="n", row_index_name="idx") // after pl.read_csv(f, row_index_name="idx")
Defensive patterns
Strategy: try-catch
Validate before calling
if old_name in kwargs and new_name in kwargs:
raise ValueError(f"pass either {old_name!r} or {new_name!r}, not both") Try / catch
try:
result = func(**kwargs)
except ArgumentRemovedError as e:
kwargs.pop(old_name, None)
result = func(**kwargs) Prevention
- During migrations, remove the old kwarg everywhere in one pass
- Avoid wrappers that merge defaults containing the new name with user-supplied legacy kwargs
- Treat ArgumentRemovedError as a code bug, not a runtime condition
When it happens
Trigger: Calling a decorated function with the old kwarg and the new kwarg simultaneously, e.g. `func(x=1, x_new=2)`, after the parameter was renamed in the removal version.
Common situations: Half-migrated code after a Polars upgrade; wrappers that merge user kwargs with defaults containing the new name while forwarding the old name; generated code mixing API generations.
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; ` ` , use ` `…
- the argument for has been removed in version . It was…
- the argument for has been removed in version .
- accessing ` ` from the top-level `polars` module was…
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/4c59d6a9c629afdf.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/_utils/expired.py:143
def _raise_removed_argument_error(
param: RemovedParameter | RenamedParameter,
*,
func_name: str,
kwargs: dict[str, object],
) -> NoReturn:
was_deprecated_and = (
f" was deprecated in version {param.deprecated_in} and"
if param.deprecated_in is not None
else ""
)
if isinstance(param, RenamedParameter):
if param.name in kwargs and param.new_name in kwargs:
msg = (
f"{func_name!r} received both {param.name!r} and {param.new_name!r} as arguments;"
f" {param.name!r}{was_deprecated_and} has been renamed to"
f" {param.new_name!r} in version {param.removed_in}."
)
raise ArgumentRemovedError(msg)
else:
msg = (
f"the argument {param.name!r} for {func_name!r}{was_deprecated_and}"
f" has been removed in version {param.removed_in}."
f" It was renamed to {param.new_name!r}."
)
msg = msg if param.hint is None else f"{msg} {param.hint}"
raise ArgumentRemovedError(msg)
elif isinstance(param, RemovedParameter):
msg = (
f"the argument {param.name!r} for {func_name!r}{was_deprecated_and}"
f" has been removed in version {param.removed_in}."
)
msg = msg if param.hint is None else f"{msg} {param.hint}"
raise ArgumentRemovedError(msg)
else:
msg = f"Unexpected parameter type: {type(param)!r}"
raise TypeError(msg)View on GitHub (pinned to fe841f959e)