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_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.
Source
Thrown at crates/polars-compute/src/rolling/nulls/min_max.rs:22
pub type MinWindow<'a, T> = MinMaxWindow<'a, T, MinPropagateNan>;
pub type MaxWindow<'a, T> = MinMaxWindow<'a, T, MaxPropagateNan>;
use super::*;
pub fn rolling_min<T>(
arr: &PrimitiveArray<T>,
window_size: usize,
min_periods: usize,
center: bool,
weights: Option<&[f64]>,
_params: Option<RollingFnParams>,
) -> ArrayRef
where
T: NativeType + IsFloat,
{
if weights.is_some() {
panic!("weights not yet supported on array with null values")
}
if center {
rolling_apply_agg_window::<MinMaxWindow<T, MinPropagateNan>, _, _, _>(
arr.values().as_slice(),
arr.validity().as_ref().unwrap(),
window_size,
min_periods,
det_offsets_center,
None,
)
} else {
rolling_apply_agg_window::<MinMaxWindow<T, MinPropagateNan>, _, _, _>(
arr.values().as_slice(),
arr.validity().as_ref().unwrap(),
window_size,
min_periods,
det_offsets,
None,View on GitHub (pinned to 9b5d73fd00)
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
Example fix
# before s.rolling_min(window_size=5, weights=w) # panics if s has nulls # after out = s.drop_nulls().rolling_min(window_size=5, weights=w).reindex(s.arg_null... ) # or simply: s.rolling_min(window_size=5) # unweighted, null-aware
Defensive patterns
Strategy: validation
Validate before calling
def safe_rolling_min(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_min")
return s.rolling_min(window_size, weights=weights, min_periods=min_periods) Try / catch
try:
out = s.rolling_min(window_size=5, weights=w)
except pl.exceptions.PanicException:
out = s.rolling_min(window_size=5, min_periods=2) # unweighted null-aware fallback Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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/a9c54ecdd17eaed1.
Report an issue: GitHub.