{"record":{"id":"0c0b6fb4e0e19de1","repo":"pola-rs/polars","slug":"didn-t-expect-so-many-arguments","errorCode":null,"errorMessage":"didn't expect so many arguments","messagePattern":"didn't expect so many arguments","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-polars/pyo3-polars-derive/src/lib.rs","lineNumber":130,"sourceCode":"        })\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 (\n            e: *mut polars_ffi::version_0::SeriesExport,\n            input_len: usize,\n            kwargs_ptr: *const u8,\n            kwargs_len: usize,\n            return_value: *mut polars_ffi::version_0::SeriesExport,\n            context: *mut polars_ffi::version_0::CallerContext\n        )  {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/pyo3-polars/pyo3-polars-derive/src/lib.rs#L112-L148","documentation":"The macro's final catch-all panics with \"didn't expect so many arguments\" (lib.rs:130) when a #[polars_expr] function has three or more parameters. Only 0, 1 (kwargs|context), or 2 (context, kwargs) parameter shapes are supported for the special-call codegen.","triggerScenarios":"Declaring #[polars_expr] on a function with 3+ parameters, e.g. fn f(a: &Series, b: &Series, c: i64) or f(context, kwargs, extra).","commonSituations":"Trying to pass multiple literal arguments positionally; converting a general Rust helper with many parameters into a plugin expression without consolidating options.","solutions":["Reduce the signature to Series parameters plus at most one `kwargs` parameter; pack all extra options into the kwargs struct.","If both context and options are needed, use exactly (context, kwargs) and nothing else.","Precompute or hardcode unneeded parameters instead of passing them through the plugin boundary."],"exampleFix":"// before\nfn f(a: &Series, b: &Series, c: i64) -> ...\n// after\nfn f(a: &Series, kwargs: Wrapped<Kw>) -> ...  // Kw { b: Series-ish, c: i64 }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cap signatures at Series parameters plus one kwargs parameter.","Bundle all options into a single kwargs struct.","Keep unrelated helpers as plain Rust functions rather than forcing them through polars_expr."],"tags":["proc-macro","compile-time","arity","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"}