pola-rs/polars · error

expected a type argument

Error message

expected a type argument

What it means

The same derive-macro signature walk panics with "expected a type argument" (lib.rs:110) when a function parameter is the receiver self (FnArg::Receiver) or otherwise not a typed pattern. #[polars_expr] functions must be free-standing functions with only typed, named parameters — methods and self receivers are rejected at compile time.

Solutions

  1. Move the function out of the impl block and make it a free function without self.
  2. Convert method state into explicit parameters (e.g. pass the Series and literals as arguments).
  3. Keep all parameters in `name: Type` form so the macro can enumerate and forward them.

Example fix

// before
impl MyOps {
    #[polars_expr(output_type=Int64)]
    fn double(&self, x: &Series) -> PolarsResult<Column> { ... }
}
// after
#[polars_expr(output_type=Int64)]
fn double(x: &Series) -> PolarsResult<Column> { ... }
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Applying #[polars_expr] (via the polars_expr macro called by polars_expr derive) to a method with self/&self parameter, or to a signature where an argument is not FnArg::Typed.

Common situations: Putting the macro on an impl-block method; writing associated functions with self; generating signatures programmatically that include receivers.

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

Appendix: source

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

    })
}

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()) {
            ("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}"),

View on GitHub (pinned to fe841f959e)