pola-rs/polars · error
weights not yet supported on array with null values
Error message
weights not yet supported on array with null values
What it means
nulls::rolling_sum, the null-handling rolling sum, panics with 'weights not yet supported on array with null values' when weights is Some. Only the null-free path implements weighted summation; the guard makes the combination an explicit failure rather than a silent wrong total.
Source
Thrown at crates/polars-compute/src/rolling/nulls/sum.rs:24
arr: &PrimitiveArray<T>,
window_size: usize,
min_periods: usize,
center: bool,
weights: Option<&[f64]>,
_params: Option<RollingFnParams>,
) -> ArrayRef
where
T: NativeType
+ IsFloat
+ PartialOrd
+ Add<Output = T>
+ Sub<Output = T>
+ SubAssign
+ AddAssign
+ NumCast,
{
if weights.is_some() {
panic!("weights not yet supported on array with null values")
}
if center {
rolling_apply_agg_window::<SumWindow<T, T>, _, _, _>(
arr.values().as_slice(),
arr.validity().as_ref().unwrap(),
window_size,
min_periods,
det_offsets_center,
None,
)
} else {
rolling_apply_agg_window::<SumWindow<T, T>, _, _, _>(
arr.values().as_slice(),
arr.validity().as_ref().unwrap(),
window_size,
min_periods,
det_offsets,
None,View on GitHub (pinned to 9b5d73fd00)
Solutions
- Compute the weighted sum manually from supported ops: fill nulls, then rolling_sum(x * w) / rolling_sum(w) for a mean or rolling_sum(x * w) directly for a decayed total
- Drop weights and use the null-aware unweighted rolling_sum
- Fill nulls (e.g. fill_null(0)) so the no-nulls weighted kernel is used, documenting the bias
- Request weighted null-aware rolling sum upstream
Example fix
# before s.rolling_sum(window_size=7, weights=[0.5, 0.7, 0.8, 0.9, 1.0, 1.0, 1.0]) # nulls -> panic # after s.fill_null(0.0).rolling_sum(window_size=7, weights=[0.5, 0.7, 0.8, 0.9, 1.0, 1.0, 1.0])
Defensive patterns
Strategy: validation
Validate before calling
def safe_rolling_sum(s: pl.Series, window_size: int, weights=None, min_periods=1):
if weights is not None and s.null_count() > 0:
raise ValueError("weights + nulls unsupported for rolling_sum; fill first or drop weights")
return s.rolling_sum(window_size, weights=weights, min_periods=min_periods) Try / catch
try:
out = s.rolling_sum(window_size=7, weights=w)
except pl.exceptions.PanicException:
out = s.fill_null(0.0).rolling_sum(window_size=7, weights=w) Prevention
- null_count() check before any weighted rolling op - it covers sum, mean, var, min/max, quantile
- Fill nulls explicitly (and record the choice) rather than letting a panic surface at query time
- Wrap rolling_* in team helpers that enforce the weights/nulls rule once
When it happens
Trigger: s.rolling_sum(window_size=k, weights=[...]) or .rolling_sum(..., weights=...) on a Series containing at least one null value; rolling sums with decay weights over nullable logs/metrics.
Common situations: Weighted moving sums over event counts with missing intervals; code ported from pandas (which tolerates NaN + weights differently) that panics under polars once nulls occur.
Related errors
- weights not yet supported on array with null values
- weights not yet supported on array with null values
- weights not yet supported on array with null values
- weights not yet supported on array with null values
- Invalid `POLARS_PQ_PREFILTERED_MASK` value '{v}'.
AI-assisted analysis of pola-rs/polars@9b5d73fd00 (2026-08-19).
Data as JSON: /api/errors/12a270a4726df2aa.
Report an issue: GitHub.