{"record":{"id":"6f37fa11d2127a14","repo":"pola-rs/polars","slug":"null-buffer-should-be-there","errorCode":null,"errorMessage":"null buffer should be there","messagePattern":"null buffer should be there","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-arrow/src/legacy/kernels/take_agg/mod.rs","lineNumber":67,"sourceCode":"\n/// Take kernel for single chunk and an iterator as index.\n/// # Safety\n/// caller must ensure iterators indexes are in bounds\n#[inline]\npub unsafe fn take_agg_primitive_iter_unchecked_count_nulls<\n    T: NativeType + ToPrimitive,\n    I: IntoIterator<Item = usize>,\n    TOut,\n    F: Fn(TOut, T) -> TOut,\n>(\n    arr: &PrimitiveArray<T>,\n    indices: I,\n    init: TOut,\n    f: F,\n    len: IdxSize,\n) -> Option<(TOut, IdxSize)> {\n    let array_values = arr.values().as_slice();\n    let validity = arr.validity().expect(\"null buffer should be there\");\n\n    let mut null_count = 0 as IdxSize;\n    let out = indices.into_iter().fold(init, |acc, idx| {\n        if validity.get_bit_unchecked(idx) {\n            f(acc, *array_values.get_unchecked(idx))\n        } else {\n            null_count += 1;\n            acc\n        }\n    });\n    if null_count == len {\n        None\n    } else {\n        Some((out, null_count))\n    }\n}\n\n/// Take kernel for single chunk and an iterator as index.","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-arrow/src/legacy/kernels/take_agg/mod.rs#L49-L85","documentation":"take_agg_primitive_iter_unchecked_count_nulls requires the array to have a validity bitmap because it must count nulls per window; it calls .expect(\"null buffer should be there\") and panics when arr.validity() is None, i.e. the kernel was invoked on a no-nulls array.","triggerScenarios":"Thrown at crates/polars-arrow/src/legacy/kernels/take_agg/mod.rs:67 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call the no-nulls variant of the take-agg kernel when validity() is None","Reify the validity bitmap (e.g. via rechunk/with_validity) before using this kernel","Add a check that selects the correct kernel based on arr.validity()"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}