{"record":{"id":"fcaf584eac41a959","repo":"pola-rs/polars","slug":"didn-t-expect-argument-a","errorCode":null,"errorMessage":"didn't expect argument {a}","messagePattern":"didn't expect argument (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-polars/pyo3-polars-derive/src/lib.rs","lineNumber":123,"sourceCode":"                    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()) {\n            (\"context\", \"kwargs\") => quote_call_context_kwargs(&ast, fn_name),\n            (\"kwargs\", \"context\") => panic!(\"'kwargs', 'context' order should be reversed\"),\n            (a, b) => panic!(\"didn't expect arguments {a}, {b}\"),\n        },\n        _ => panic!(\"didn't expect so many arguments\"),\n    };\n\n    let quote_process_result = quote_process_results();\n    let fn_name = get_expression_function_name(fn_name);\n\n    quote!(\n        use ::pyo3_polars::export::*;\n\n        // create the outer public function\n        #[no_mangle]\n        pub unsafe extern \"C\" fn #fn_name (","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/pyo3-polars/pyo3-polars-derive/src/lib.rs#L105-L141","documentation":"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.","triggerScenarios":"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\".","commonSituations":"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.","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."],"exampleFix":"// before\n#[polars_expr(output_type=Int64)]\nfn scale(x: &Series, factor: i64) -> PolarsResult<Column> { ... }\n// after\n#[polars_expr(output_type=Int64)]\nfn scale(x: &Series, kwargs: Wrapped<MyKwargs>) -> PolarsResult<Column> { ... }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["proc-macro","compile-time","kwargs","rust","polars"],"backgroundTag":"missing-required-option","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"}