pola-rs/polars · error

expected an argument

Error message

expected an argument

What it means

While generating code for a #[polars_expr] function, the macro walks the function's signature arguments and panics with "expected an argument" (lib.rs:107) when a typed parameter's pattern is not a simple identifier — e.g. a pattern like (a, b), Some(x), or a struct destructuring. The macro only knows how to forward plain named parameters.

Solutions

  1. Replace destructured parameters with simple identifiers and destructure inside the function body.
  2. Keep each parameter a plain named binding (ident: Type) so the macro can forward it.
  3. Bind complex inputs to a single parameter (e.g. a Series or kwargs struct) and unpack inside the function.

Example fix

// before
#[polars_expr(output_type=Int64)]
fn add((a, b): (i64, i64)) -> i64 { a + b }
// after
#[polars_expr(output_type=Int64)]
fn add(a: i64, b: i64) -> i64 { a + b }
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Declaring an expression function with destructured or complex parameter patterns: fn f((a, b): (i64, i64)), fn f(Some(x): Option<i64>), or any non-ident binding pattern passed through the derive macro at compile time.

Common situations: Attempting tuple destructuring for convenience; macro-generated or hand-edited signatures; porting functions written for plain Rust use to the plugin macro without simplifying parameters.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/dd19cd1ff0d1d5e5. Report an issue: GitHub.

Appendix: source

Thrown at pyo3-polars/pyo3-polars-derive/src/lib.rs:107

            // Set latest error, but leave return value in empty state.
            pyo3_polars::derive::_update_last_error(err);
        },
    })
}

fn create_expression_function(ast: syn::ItemFn) -> proc_macro2::TokenStream {
    // count how often the user define a kwargs argument.
    let args = ast
        .sig
        .inputs
        .iter()
        .skip(1)
        .map(|fn_arg| {
            if let FnArg::Typed(pat) = fn_arg {
                if let syn::Pat::Ident(pat) = pat.pat.as_ref() {
                    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()) {

View on GitHub (pinned to fe841f959e)