diff --git a/crates/polars-ops/src/chunked_array/interpolate.rs b/crates/polars-ops/src/chunked_array/interpolate.rs index 7bab1e609758..b06c06574960 100644 --- a/crates/polars-ops/src/chunked_array/interpolate.rs +++ b/crates/polars-ops/src/chunked_array/interpolate.rs @@ -60,29 +60,6 @@ where } } -#[inline] -fn unsigned_interp(low: T, high: T, steps: IdxSize, steps_n: T, av: &mut Vec) -where - T: Sub - + Mul - + Add - + Div - + NumCast - + PartialOrd - + Copy, -{ - if high >= low { - signed_interp::(low, high, steps, steps_n, av) - } else { - let diff = low - high; - for step_i in (1..steps).rev() { - let step_i: T = NumCast::from(step_i).unwrap(); - let v = linear_itp(high, step_i, diff, steps_n); - av.push(v) - } - } -} - fn interpolate_impl(chunked_arr: &ChunkedArray, interpolation_branch: I) -> ChunkedArray where T: PolarsNumericType, @@ -196,16 +173,34 @@ fn interpolate_linear(s: &Series) -> Series { let logical = s.dtype(); let s = s.to_physical_repr(); - let out = match s.dtype() { - DataType::Float32 => linear_interp_signed(s.f32().unwrap()), - DataType::Float64 => linear_interp_signed(s.f64().unwrap()), - DataType::UInt8 | DataType::UInt16 | DataType::UInt32 | DataType::UInt64 => { - linear_interp_unsigned(s.cast(&DataType::Float64).unwrap().f64().unwrap()) - }, - DataType::Int8 | DataType::Int16 | DataType::Int32 | DataType::Int64 => { - linear_interp_signed(s.cast(&DataType::Float64).unwrap().f64().unwrap()) - }, - _ => s.as_ref().clone(), + + let out = if matches!( + logical, + DataType::Date | DataType::Datetime(_, _) | DataType::Duration(_) | DataType::Time + ) { + match s.dtype() { + // Datetime, Time, or Duration + DataType::Int64 => linear_interp_signed(s.i64().unwrap()), + // Date + DataType::Int32 => linear_interp_signed(s.i32().unwrap()), + _ => unreachable!(), + } + } else { + match s.dtype() { + DataType::Float32 => linear_interp_signed(s.f32().unwrap()), + DataType::Float64 => linear_interp_signed(s.f64().unwrap()), + DataType::Int8 + | DataType::Int16 + | DataType::Int32 + | DataType::Int64 + | DataType::UInt8 + | DataType::UInt16 + | DataType::UInt32 + | DataType::UInt64 => { + linear_interp_signed(s.cast(&DataType::Float64).unwrap().f64().unwrap()) + }, + _ => s.as_ref().clone(), + } }; match logical { DataType::Date @@ -218,12 +213,6 @@ fn interpolate_linear(s: &Series) -> Series { } } -fn linear_interp_unsigned(ca: &ChunkedArray) -> Series -where - ChunkedArray: IntoSeries, -{ - interpolate_impl(ca, unsigned_interp::).into_series() -} fn linear_interp_signed(ca: &ChunkedArray) -> Series where ChunkedArray: IntoSeries,