-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve rolling_sum/rolling_mean for windows with null values. (#3466)
* improve rolling_sum nulls * refactor rolling kernel modules * improve rolling mean nulls
- Loading branch information
Showing
11 changed files
with
274 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rrow/src/kernels/rolling/mean_no_nulls.rs → ...rrow/src/kernels/rolling/no_nulls/mean.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use super::sum::SumWindow; | ||
use super::*; | ||
use super::{rolling_apply_agg_window, RollingAggWindow}; | ||
|
||
struct MeanWindow<'a, T> { | ||
sum: SumWindow<'a, T>, | ||
} | ||
|
||
impl< | ||
'a, | ||
T: NativeType | ||
+ IsFloat | ||
+ PartialOrd | ||
+ Add<Output = T> | ||
+ Sub<Output = T> | ||
+ NumCast | ||
+ Div<Output = T>, | ||
> RollingAggWindow<'a, T> for MeanWindow<'a, T> | ||
{ | ||
unsafe fn new( | ||
slice: &'a [T], | ||
validity: &'a Bitmap, | ||
start: usize, | ||
end: usize, | ||
min_periods: usize, | ||
) -> Self { | ||
Self { | ||
sum: SumWindow::new(slice, validity, start, end, min_periods), | ||
} | ||
} | ||
|
||
unsafe fn update(&mut self, start: usize, end: usize) -> Option<T> { | ||
let sum = self.sum.update(start, end); | ||
dbg!(sum); | ||
sum.map(|sum| sum / NumCast::from(end - start - self.sum.null_count).unwrap()) | ||
} | ||
} | ||
|
||
pub fn rolling_mean<T>( | ||
arr: &PrimitiveArray<T>, | ||
window_size: usize, | ||
min_periods: usize, | ||
center: bool, | ||
weights: Option<&[f64]>, | ||
) -> ArrayRef | ||
where | ||
T: NativeType | ||
+ IsFloat | ||
+ PartialOrd | ||
+ Add<Output = T> | ||
+ Sub<Output = T> | ||
+ NumCast | ||
+ Div<Output = T>, | ||
{ | ||
if weights.is_some() { | ||
panic!("weights not yet supported on array with null values") | ||
} | ||
if center { | ||
rolling_apply_agg_window::<MeanWindow<_>, _, _>( | ||
arr.values().as_slice(), | ||
arr.validity().as_ref().unwrap(), | ||
window_size, | ||
min_periods, | ||
det_offsets_center, | ||
) | ||
} else { | ||
rolling_apply_agg_window::<MeanWindow<_>, _, _>( | ||
arr.values().as_slice(), | ||
arr.validity().as_ref().unwrap(), | ||
window_size, | ||
min_periods, | ||
det_offsets, | ||
) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.