{"record":{"id":"fe229c1dbdc6ffa2","repo":"pola-rs/polars","slug":"didn-t-understand-polars-expr-attribute","errorCode":null,"errorMessage":"didn't understand polars_expr attribute","messagePattern":"didn't understand polars_expr attribute","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-polars/pyo3-polars-derive/src/lib.rs","lineNumber":275,"sourceCode":"            let out = polars_arrow::ffi::export_field_to_c(&out.to_arrow(polars_core::datatypes::CompatLevel::newest()));\n            *return_value = out;\n        }\n    )\n}\n\n#[proc_macro_attribute]\npub fn polars_expr(attr: TokenStream, input: TokenStream) -> TokenStream {\n    let ast = parse_macro_input!(input as syn::ItemFn);\n\n    let options = parse_macro_input!(attr as attr::ExprsFunctionOptions);\n    let expanded_field_fn = if let Some(fn_name) = options.output_type_fn {\n        create_field_function(&ast.sig.ident, &fn_name, false)\n    } else if let Some(fn_name) = options.output_type_fn_kwargs {\n        create_field_function(&ast.sig.ident, &fn_name, true)\n    } else if let Some(dtype) = options.output_dtype {\n        create_field_function_from_with_dtype(&ast.sig.ident, dtype)\n    } else {\n        panic!(\"didn't understand polars_expr attribute\")\n    };\n\n    let expanded_expr = create_expression_function(ast);\n    let expanded = quote!(\n        #expanded_field_fn\n\n        #expanded_expr\n    );\n    TokenStream::from(expanded)\n}\n","sourceCodeStart":257,"sourceCodeEnd":286,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/pyo3-polars/pyo3-polars-derive/src/lib.rs#L257-L286","documentation":"The #[polars_expr] entry macro must generate an output-field function; if none of output_type_fn, output_type_fn_kwargs, or output_dtype was set in the parsed attributes, it panics with \"didn't understand polars_expr attribute\" (lib.rs:275). This is the public macro's guard against a #[polars_expr] usage that does not declare how to compute the return dtype.","triggerScenarios":"Using #[polars_expr(...)] with no output-dtype-producing attribute (no output_type/dtype alias, no output_type_func, no output_type_func_with_kwargs), or with only attributes the field-fn generation path doesn't consume.","commonSituations":"Omitting output_type on a new expression function; renaming/refactoring that dropped the output_type_func reference; following an example for a different macro (#[polars] vs #[polars_expr]) whose attribute sets differ.","solutions":["Add an output type declaration, e.g. #[polars_expr(output_type=Int64)] or the appropriate dtype alias.","If the dtype depends on inputs, supply #[polars_expr(output_type_func=\"my_field_fn\")] (or output_type_func_with_kwargs) pointing to a function returning the DataType.","Verify you are using #[polars_expr] with its attribute set, not #[polars] attributes, and that the referenced function name is in scope."],"exampleFix":"// before\n#[polars_expr]\nfn my_expr(x: &Series) -> PolarsResult<Column> { ... }\n// after\n#[polars_expr(output_type=Int64)]\nfn my_expr(x: &Series) -> PolarsResult<Column> { ... }","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Every #[polars_expr] must declare output_type, a dtype alias, or an output_type_func.","Reference an existing in-scope field function when using output_type_func.","Compare against the crate's example macros when migrating between pyo3-polars versions."],"tags":["proc-macro","compile-time","attribute","rust","polars"],"backgroundTag":"missing-required-config-field","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"}