pola-rs/polars · error
didn't expect argument
Error message
didn't expect argument {a} What it means
After collecting parameter names, the macro dispatches on them: a single parameter named "kwargs" or "context" gets special codegen, and any other single name falls into panic!("didn't expect argument {a}") (lib.rs:123). This fires when a polars_expr function has exactly one argument whose name is neither kwargs nor context — i.e. the generated call path assumes every one-arg function uses the special kwargs/context protocol.
Solutions
- Add the kwargs parameter: change the signature to take kwargs: Wrapped<(...)> (or a dedicated kwargs struct) and read your arguments from it.
- If the argument is expression context, name the parameter `context`.
- Take zero special arguments and instead supply extra values via kwargs alongside your typed Series parameters as supported by your pyo3-polars version.
Example fix
// before
#[polars_expr(output_type=Int64)]
fn scale(x: &Series, factor: i64) -> PolarsResult<Column> { ... }
// after
#[polars_expr(output_type=Int64)]
fn scale(x: &Series, kwargs: Wrapped<MyKwargs>) -> PolarsResult<Column> { ... } Defensive patterns
Strategy: validation
Prevention
- Pass extra arguments via a kwargs parameter, not extra positional parameters.
- Learn the accepted parameter-name protocol: (), (kwargs), (context), (context, kwargs).
- Check example plugins in the pyo3-polars repo before designing signatures.
When it happens
Trigger: Declaring #[polars_expr] on a function taking exactly one plain positional argument (e.g. fn f(x: i64)) — the macro's 1-arg match arm only accepts "kwargs" or "context".
Common situations: Writing a one-parameter expression function expecting a single literal/Series argument; forgetting that normal arguments must go through kwargs; older examples using a different calling convention.
Understand the failure class
Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.
Related errors
- data type must be FixedSizeList
- didn't recognize attribute
- didn't understand polars_expr attribute
- offset + length overflowed
- validity must be equal to the array's length
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/fcaf584eac41a959.
Report an issue: GitHub.
Appendix: source
Thrown at pyo3-polars/pyo3-polars-derive/src/lib.rs:123
pat.ident.to_string()
} else {
panic!("expected an argument")
}
} else {
panic!("expected a type argument")
}
})
.collect::<Vec<_>>();
let fn_name = &ast.sig.ident;
// Get the tokenstream of the call logic.
let quote_call = match args.len() {
0 => quote_call_no_kwargs(&ast, fn_name),
1 => match args[0].as_str() {
"kwargs" => quote_call_kwargs(&ast, fn_name),
"context" => quote_call_context(&ast, fn_name),
a => panic!("didn't expect argument {a}"),
},
2 => match (args[0].as_str(), args[1].as_str()) {
("context", "kwargs") => quote_call_context_kwargs(&ast, fn_name),
("kwargs", "context") => panic!("'kwargs', 'context' order should be reversed"),
(a, b) => panic!("didn't expect arguments {a}, {b}"),
},
_ => panic!("didn't expect so many arguments"),
};
let quote_process_result = quote_process_results();
let fn_name = get_expression_function_name(fn_name);
quote!(
use ::pyo3_polars::export::*;
// create the outer public function
#[no_mangle]
pub unsafe extern "C" fn #fn_name (View on GitHub (pinned to fe841f959e)