pola-rs/polars · error

didn't expect arguments

Error message

didn't expect arguments {a}, {b}

What it means

The two-argument arm accepts only ("context", "kwargs"); any other name pair hits panic!("didn't expect arguments {a}, {b}") (lib.rs:128). This is the compile-time guard ensuring polars_expr functions use only the recognized special-parameter combinations.

Solutions

  1. Rename the parameters to exactly (context, kwargs) if you need both special inputs.
  2. Otherwise move extra inputs into the kwargs struct and keep only Series/typed parameters plus the kwargs parameter per your version's convention.
  3. Consult pyo3-polars-derive docs for the allowed parameter-name combos: (), (kwargs), (context), (context, kwargs).

Example fix

// before
fn f(series: &Series, opts: Wrapped<Kw>) -> ...
// after
fn f(context: &Context, kwargs: Wrapped<Kw>) -> ...
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Declaring a #[polars_expr] function with two parameters not exactly named context and kwargs in that order — e.g. (a, b), (series, kwargs), (kwargs, other).

Common situations: Trying to pass two typed Series parameters directly; inventing custom parameter names for the special two-arg protocol.

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/b9a97c7adfbf875d. Report an issue: GitHub.

Appendix: source

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

                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 (
            e: *mut polars_ffi::version_0::SeriesExport,
            input_len: usize,
            kwargs_ptr: *const u8,
            kwargs_len: usize,
            return_value: *mut polars_ffi::version_0::SeriesExport,

View on GitHub (pinned to fe841f959e)