{"record":{"id":"dd19cd1ff0d1d5e5","repo":"pola-rs/polars","slug":"expected-an-argument","errorCode":null,"errorMessage":"expected an argument","messagePattern":"expected an argument","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-polars/pyo3-polars-derive/src/lib.rs","lineNumber":107,"sourceCode":"            // Set latest error, but leave return value in empty state.\n            pyo3_polars::derive::_update_last_error(err);\n        },\n    })\n}\n\nfn create_expression_function(ast: syn::ItemFn) -> proc_macro2::TokenStream {\n    // count how often the user define a kwargs argument.\n    let args = ast\n        .sig\n        .inputs\n        .iter()\n        .skip(1)\n        .map(|fn_arg| {\n            if let FnArg::Typed(pat) = fn_arg {\n                if let syn::Pat::Ident(pat) = pat.pat.as_ref() {\n                    pat.ident.to_string()\n                } else {\n                    panic!(\"expected an argument\")\n                }\n            } else {\n                panic!(\"expected a type argument\")\n            }\n        })\n        .collect::<Vec<_>>();\n\n    let fn_name = &ast.sig.ident;\n\n    // Get the tokenstream of the call logic.\n    let quote_call = match args.len() {\n        0 => quote_call_no_kwargs(&ast, fn_name),\n        1 => match args[0].as_str() {\n            \"kwargs\" => quote_call_kwargs(&ast, fn_name),\n            \"context\" => quote_call_context(&ast, fn_name),\n            a => panic!(\"didn't expect argument {a}\"),\n        },\n        2 => match (args[0].as_str(), args[1].as_str()) {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/pyo3-polars/pyo3-polars-derive/src/lib.rs#L89-L125","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Replace destructured parameters with simple identifiers and destructure inside the function body.","Keep each parameter a plain named binding (ident: Type) so the macro can forward it.","Bind complex inputs to a single parameter (e.g. a Series or kwargs struct) and unpack inside the function."],"exampleFix":"// before\n#[polars_expr(output_type=Int64)]\nfn add((a, b): (i64, i64)) -> i64 { a + b }\n// after\n#[polars_expr(output_type=Int64)]\nfn add(a: i64, b: i64) -> i64 { a + b }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use plain `name: Type` parameters in polars_expr functions.","Destructure inside the function body, not in the signature.","Review signatures after code generation or refactors that touch parameter patterns."],"tags":["proc-macro","compile-time","function-signature","rust"],"backgroundTag":"invalid-argument-format","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}