{"record":{"id":"a9c54ecdd17eaed1","repo":"pola-rs/polars","slug":"weights-not-yet-supported-on-array-with-null-value-a9c54e","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/min_max.rs","lineNumber":22,"sourceCode":"\npub type MinWindow<'a, T> = MinMaxWindow<'a, T, MinPropagateNan>;\npub type MaxWindow<'a, T> = MinMaxWindow<'a, T, MaxPropagateNan>;\n\nuse super::*;\n\npub fn rolling_min<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 + IsFloat,\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::<MinMaxWindow<T, MinPropagateNan>, _, _, _>(\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::<MinMaxWindow<T, MinPropagateNan>, _, _, _>(\n            arr.values().as_slice(),\n            arr.validity().as_ref().unwrap(),\n            window_size,\n            min_periods,\n            det_offsets,\n            None,","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/pola-rs/polars/blob/9b5d73fd00236295624374b075d16b1fe6ec6df9/crates/polars-compute/src/rolling/nulls/min_max.rs#L4-L40","documentation":"nulls::rolling_min, the null-handling rolling minimum in polars-compute, begins with a panic guard: if weights is Some(_) on an array with nulls it panics 'weights not yet supported on array with null values'. Weighted rolling min/max has no correct definition on the null path, so the guard refuses instead of guessing.","triggerScenarios":"s.rolling_min(window_size=k, weights=[...]) or the equivalent expression on a Series containing at least one null; group_by aggregations where some groups contain nulls and a weights vector is passed.","commonSituations":"Rolling-window feature engineering (min over trailing k periods) with a decay/exp weighting vector applied to nullable market or sensor data; the same query ran unweighted or on cleaned data without issue.","solutions":["Drop weights for nullable input - unweighted rolling_min handles nulls correctly","Fill nulls first (s.fill_null(strategy)) and be explicit about how filling interacts with min","Compute on s.drop_nulls() and reindex afterwards if alignment permits","Request/implement weighted null-aware rolling min upstream"],"exampleFix":"# before\ns.rolling_min(window_size=5, weights=w)  # panics if s has nulls\n# after\nout = s.drop_nulls().rolling_min(window_size=5, weights=w).reindex(s.arg_null... )\n# or simply: s.rolling_min(window_size=5)  # unweighted, null-aware","handlingStrategy":"validation","validationCode":"def safe_rolling_min(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_min\")\n    return s.rolling_min(window_size, weights=weights, min_periods=min_periods)","typeGuard":null,"tryCatchPattern":"try:\n    out = s.rolling_min(window_size=5, weights=w)\nexcept pl.exceptions.PanicException:\n    out = s.rolling_min(window_size=5, min_periods=2)  # unweighted null-aware fallback","preventionTips":["Gate weights on null_count() == 0 for rolling min/max","Forward-fill or drop nulls before weighted rolling features","Keep weighting vectors optional with a null-safe default in shared code"],"tags":["polars","rolling","rolling-min","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"}