{"record":{"id":"12a270a4726df2aa","repo":"pola-rs/polars","slug":"weights-not-yet-supported-on-array-with-null-value-12a270","errorCode":null,"errorMessage":"weights not yet supported on array with null values","messagePattern":"weights not yet supported on array with null values","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-compute/src/rolling/nulls/sum.rs","lineNumber":24,"sourceCode":"    arr: &PrimitiveArray<T>,\n    window_size: usize,\n    min_periods: usize,\n    center: bool,\n    weights: Option<&[f64]>,\n    _params: Option<RollingFnParams>,\n) -> ArrayRef\nwhere\n    T: NativeType\n        + IsFloat\n        + PartialOrd\n        + Add<Output = T>\n        + Sub<Output = T>\n        + SubAssign\n        + AddAssign\n        + NumCast,\n{\n    if weights.is_some() {\n        panic!(\"weights not yet supported on array with null values\")\n    }\n    if center {\n        rolling_apply_agg_window::<SumWindow<T, T>, _, _, _>(\n            arr.values().as_slice(),\n            arr.validity().as_ref().unwrap(),\n            window_size,\n            min_periods,\n            det_offsets_center,\n            None,\n        )\n    } else {\n        rolling_apply_agg_window::<SumWindow<T, T>, _, _, _>(\n            arr.values().as_slice(),\n            arr.validity().as_ref().unwrap(),\n            window_size,\n            min_periods,\n            det_offsets,\n            None,","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/crates/polars-compute/src/rolling/nulls/sum.rs#L6-L42","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\ns.rolling_sum(window_size=7, weights=[0.5, 0.7, 0.8, 0.9, 1.0, 1.0, 1.0])  # nulls -> panic\n# after\ns.fill_null(0.0).rolling_sum(window_size=7, weights=[0.5, 0.7, 0.8, 0.9, 1.0, 1.0, 1.0])","handlingStrategy":"validation","validationCode":"def safe_rolling_sum(s: pl.Series, window_size: int, weights=None, min_periods=1):\n    if weights is not None and s.null_count() > 0:\n        raise ValueError(\"weights + nulls unsupported for rolling_sum; fill first or drop weights\")\n    return s.rolling_sum(window_size, weights=weights, min_periods=min_periods)","typeGuard":null,"tryCatchPattern":"try:\n    out = s.rolling_sum(window_size=7, weights=w)\nexcept pl.exceptions.PanicException:\n    out = s.fill_null(0.0).rolling_sum(window_size=7, weights=w)","preventionTips":["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"],"tags":["polars","rolling","rolling-sum","weights","null-values","panic"],"backgroundTag":"rolling-weights-with-nulls","analyzedSha":"9b5d73fd00236295624374b075d16b1fe6ec6df9","analyzedAt":"2026-08-19T12:15:06.350Z","contentChangedAt":"2026-08-19T12:15:06.350Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}