polars_core/chunked_array/ops/aggregate/
var.rsuse polars_compute::var_cov::VarState;
use super::*;
pub trait VarAggSeries {
fn var_reduce(&self, ddof: u8) -> Scalar;
fn std_reduce(&self, ddof: u8) -> Scalar;
}
impl<T> ChunkVar for ChunkedArray<T>
where
T: PolarsNumericType,
ChunkedArray<T>: ChunkAgg<T::Native>,
{
fn var(&self, ddof: u8) -> Option<f64> {
let mut out = VarState::default();
for arr in self.downcast_iter() {
out.combine(&polars_compute::var_cov::var(arr))
}
out.finalize(ddof)
}
fn std(&self, ddof: u8) -> Option<f64> {
self.var(ddof).map(|var| var.sqrt())
}
}
impl ChunkVar for StringChunked {}
impl ChunkVar for ListChunked {}
#[cfg(feature = "dtype-array")]
impl ChunkVar for ArrayChunked {}
#[cfg(feature = "object")]
impl<T: PolarsObject> ChunkVar for ObjectChunked<T> {}
impl ChunkVar for BooleanChunked {}