pola-rs/polars · error
null buffer should be there
Error message
null buffer should be there
What it means
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.
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()
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/polars-arrow/src/legacy/kernels/take_agg/mod.rs:67 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/6f37fa11d2127a14.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-arrow/src/legacy/kernels/take_agg/mod.rs:67
/// Take kernel for single chunk and an iterator as index.
/// # Safety
/// caller must ensure iterators indexes are in bounds
#[inline]
pub unsafe fn take_agg_primitive_iter_unchecked_count_nulls<
T: NativeType + ToPrimitive,
I: IntoIterator<Item = usize>,
TOut,
F: Fn(TOut, T) -> TOut,
>(
arr: &PrimitiveArray<T>,
indices: I,
init: TOut,
f: F,
len: IdxSize,
) -> Option<(TOut, IdxSize)> {
let array_values = arr.values().as_slice();
let validity = arr.validity().expect("null buffer should be there");
let mut null_count = 0 as IdxSize;
let out = indices.into_iter().fold(init, |acc, idx| {
if validity.get_bit_unchecked(idx) {
f(acc, *array_values.get_unchecked(idx))
} else {
null_count += 1;
acc
}
});
if null_count == len {
None
} else {
Some((out, null_count))
}
}
/// Take kernel for single chunk and an iterator as index.View on GitHub (pinned to fe841f959e)