{"record":{"id":"74331c1ed0b64e44","repo":"pola-rs/polars","slug":"kwargs-context-order-should-be-reversed","errorCode":null,"errorMessage":"'kwargs', 'context' order should be reversed","messagePattern":"'kwargs', 'context' order should be reversed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-polars/pyo3-polars-derive/src/lib.rs","lineNumber":127,"sourceCode":"            } 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 (\n            e: *mut polars_ffi::version_0::SeriesExport,\n            input_len: usize,\n            kwargs_ptr: *const u8,\n            kwargs_len: usize,","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/pyo3-polars/pyo3-polars-derive/src/lib.rs#L109-L145","documentation":"For two-argument special functions, the macro accepts only the order (context, kwargs); the (kwargs, context) order panics with \"'kwargs', 'context' order should be reversed\" (lib.rs:127). The codegen always assumes the context parameter comes first, so declaring them in the opposite order is a compile-time error.","triggerScenarios":"Writing fn f(kwargs: Wrapped<K>, context: PlCausedBy/SpecialEqContext-style param) — i.e. kwargs declared before context — on a #[polars_expr] function.","commonSituations":"Copying the two-arg pattern from memory and getting the order wrong; refactoring a (context) function to add kwargs by appending it at the end.","solutions":["Reorder the parameters so `context` is the first argument and `kwargs` the second.","Rebuild after reordering; the panic message itself tells you the required order."],"exampleFix":"// before\nfn f(kwargs: Wrapped<Kw>, context: &Context) -> ... \n// after\nfn f(context: &Context, kwargs: Wrapped<Kw>) -> ...","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["When using both, always declare (context, kwargs) in that order.","When adding kwargs to an existing context function, insert it after context, not before."],"tags":["proc-macro","compile-time","argument-order","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"}