{"record":{"id":"9353e666a71877de","repo":"pola-rs/polars","slug":"weights-not-yet-supported-on-array-with-null-value-9353e6","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/moment.rs","lineNumber":20,"sourceCode":"\nuse num_traits::{FromPrimitive, ToPrimitive};\n\npub use super::super::moment::*;\nuse super::*;\n\npub fn rolling_var<T>(\n    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 + ToPrimitive + FromPrimitive + IsFloat + Float,\n{\n    if weights.is_some() {\n        panic!(\"weights not yet supported on array with null values\")\n    }\n    let offsets_fn = if center {\n        det_offsets_center\n    } else {\n        det_offsets\n    };\n    rolling_apply_agg_window::<MomentWindow<_, VarianceMoment>, _, _, _>(\n        arr.values().as_slice(),\n        arr.validity().as_ref().unwrap(),\n        window_size,\n        min_periods,\n        offsets_fn,\n        params,\n    )\n}\n\npub fn rolling_skew<T>(\n    arr: &PrimitiveArray<T>,","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/crates/polars-compute/src/rolling/nulls/moment.rs#L2-L38","documentation":"nulls::rolling_var (which also backs rolling_std) computes variance over windows with null values, but its first statement panics if weights is Some. Weighted variance/std on the null-handling path is unimplemented, so nullable input plus a weights vector aborts with 'weights not yet supported on array with null values'.","triggerScenarios":"s.rolling_std(..., weights=...) or s.rolling_var(window_size=k, weights=[...]) on a Series containing nulls; volatility computations over price series with missing bars; .rolling_std_by with weights on nullable time index data.","commonSituations":"Risk/volatility pipelines: weighted rolling std over returns where some returns are null (holidays, illiquid periods); passes on synthetic complete data, panics on production gaps.","solutions":["Remove weights and use the null-aware unweighted rolling_var/rolling_std","Fill nulls before computing (document how filling biases variance) - s.fill_null(0.0).rolling_std(..., weights=...)","Compute on drop_nulls() output and reindex where alignment allows","Push for weighted null-aware variance support upstream"],"exampleFix":"# before\ns.rolling_std(window_size=20, weights=w)  # panics when s has nulls\n# after\ns.fill_null(0.0).rolling_std(window_size=20, weights=w)","handlingStrategy":"validation","validationCode":"def safe_rolling_std(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_var/std\")\n    return s.rolling_std(window_size, weights=weights, min_periods=min_periods)","typeGuard":null,"tryCatchPattern":"try:\n    out = s.rolling_std(window_size=20, weights=w)\nexcept pl.exceptions.PanicException:\n    out = s.fill_null(0.0).rolling_std(window_size=20, weights=w)  # document the variance bias","preventionTips":["Check null_count() before weights on volatility pipelines","Consider interpolating missing returns before weighted std","Add data-completeness alerts so nulls never surprise weighted rolling jobs"],"tags":["polars","rolling","rolling-var","rolling-std","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"}