Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-compute/src/rolling/nulls/mean.rs
8426 views
1
#![allow(unsafe_op_in_unsafe_fn)]
2
use super::super::mean::MeanWindow;
3
use super::*;
4
5
pub fn rolling_mean<T>(
6
arr: &PrimitiveArray<T>,
7
window_size: usize,
8
min_periods: usize,
9
center: bool,
10
weights: Option<&[f64]>,
11
_params: Option<RollingFnParams>,
12
) -> ArrayRef
13
where
14
T: NativeType
15
+ IsFloat
16
+ PartialOrd
17
+ Add<Output = T>
18
+ Sub<Output = T>
19
+ NumCast
20
+ AddAssign
21
+ SubAssign
22
+ Div<Output = T>,
23
{
24
if weights.is_some() {
25
panic!("weights not yet supported on array with null values")
26
}
27
if center {
28
rolling_apply_agg_window::<MeanWindow<T>, _, _, _>(
29
arr.values().as_slice(),
30
arr.validity().as_ref().unwrap(),
31
window_size,
32
min_periods,
33
det_offsets_center,
34
None,
35
)
36
} else {
37
rolling_apply_agg_window::<MeanWindow<T>, _, _, _>(
38
arr.values().as_slice(),
39
arr.validity().as_ref().unwrap(),
40
window_size,
41
min_periods,
42
det_offsets,
43
None,
44
)
45
}
46
}
47
48