pola-rs/polars · error
expected float
Error message
expected float
What it means
Panic in the NaN-propagating min/max helpers: the series dtype did not match any float branch (f16/f32/f64), so the s.fNN() downcast returned None. These functions must only be called on float columns; guard the dtype before calling.
Source
Thrown at crates/polars-ops/src/chunked_array/nan_propagating_aggregate.rs:49
.reduce(min_or_max_fn)
}
pub fn nan_min_s(s: &Series, name: PlSmallStr) -> Series {
match s.dtype() {
#[cfg(feature = "dtype-f16")]
DataType::Float16 => {
let ca = s.f16().unwrap();
Series::new(name, [ca_nan_agg(ca, MinMax::min_propagate_nan)])
},
DataType::Float32 => {
let ca = s.f32().unwrap();
Series::new(name, [ca_nan_agg(ca, MinMax::min_propagate_nan)])
},
DataType::Float64 => {
let ca = s.f64().unwrap();
Series::new(name, [ca_nan_agg(ca, MinMax::min_propagate_nan)])
},
_ => panic!("expected float"),
}
}
pub fn nan_max_s(s: &Series, name: PlSmallStr) -> Series {
match s.dtype() {
#[cfg(feature = "dtype-f16")]
DataType::Float16 => {
let ca = s.f16().unwrap();
Series::new(name, [ca_nan_agg(ca, MinMax::max_propagate_nan)])
},
DataType::Float32 => {
let ca = s.f32().unwrap();
Series::new(name, [ca_nan_agg(ca, MinMax::max_propagate_nan)])
},
DataType::Float64 => {
let ca = s.f64().unwrap();
Series::new(name, [ca_nan_agg(ca, MinMax::max_propagate_nan)])
},View on GitHub (pinned to 9b5d73fd00)
Solutions
- Pass a float-typed column to this NaN-propagating aggregation; integer columns do not have NaNs.
- Cast the column to Float64/Float32 before aggregating.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: This panic/expect fires when execution reaches an unguarded state described by: "expected float". Typical triggers: unsupported dtype or feature-gated code path reached at runtime, invalid user input or environment variable value, calling API methods in the wrong order or on mismatched types, or data (lengths, offsets, ranges) violating the function's preconditions.
Common situations: Encountered when input data or configuration does not meet the preconditions of the throwing code path ("expected float"). Common cases: missing Cargo feature flags, mismatched dtypes/lengths between arrays or series, out-of-range temporal values, malformed environment variables, or operations on unsupported/complex nested types.
AI-assisted analysis of pola-rs/polars@9b5d73fd00 (2026-08-19).
Data as JSON: /api/errors/eaa6a30dd6c79991.
Report an issue: GitHub.