Skip to content

Commit

Permalink
add test, remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
marcvanheerden authored and ritchie46 committed Feb 2, 2022
1 parent c26b638 commit 3936272
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
35 changes: 0 additions & 35 deletions polars/polars-arrow/src/kernels/rolling/no_nulls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,6 @@ impl Default for QuantileInterpolOptions {
}
}

fn rolling_apply_convolve<Fo, Fa>(
values: &[f64],
window_size: usize,
min_periods: usize,
det_offsets_fn: Fo,
aggregator: Fa,
weights: &[f64],
) -> ArrayRef
where
Fo: Fn(Idx, WindowSize, Len) -> (Start, End),
Fa: Fn(&[f64]) -> f64,
{
assert_eq!(weights.len(), window_size);
let mut buf = vec![0.0; window_size];
let len = values.len();
let out = (0..len)
.map(|idx| {
let (start, end) = det_offsets_fn(idx, window_size, len);
let vals = unsafe { values.get_unchecked(start..end) };
buf.iter_mut()
.zip(vals.iter().zip(weights))
.for_each(|(b, (v, w))| *b = *v * *w);

aggregator(&buf)
})
.collect_trusted::<Vec<f64>>();

let validity = create_validity(min_periods, len as usize, window_size, det_offsets_fn);
Arc::new(PrimitiveArray::from_data(
DataType::Float64,
out.into(),
validity.map(|b| b.into()),
))
}

fn rolling_apply_weights<Fo, Fa>(
values: &[f64],
window_size: usize,
Expand Down
8 changes: 4 additions & 4 deletions py-polars/tests/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,19 +730,19 @@ def test_rolling_apply() -> None:
assert (roll_app_sum - roll_sum).abs().sum() < 0.0001

s = pl.Series("A", list(range(6)), dtype=pl.Float64)
roll_app_sum = s.rolling_apply(
function=lambda s: s.sum(),
roll_app_std = s.rolling_apply(
function=lambda s: s.std(),
window_size=4,
weights=[1.0, 2.0, 3.0, 0.1],
min_periods=3,
center=False,
)

roll_sum = s.rolling_sum(
roll_std = s.rolling_std(
window_size=4, weights=[1.0, 2.0, 3.0, 0.1], min_periods=3, center=False
)

assert (roll_app_sum - roll_sum).abs().sum() < 0.0001
assert (roll_app_std - roll_std).abs().sum() < 0.0001


def test_arr_namespace(fruits_cars: pl.DataFrame) -> None:
Expand Down

0 comments on commit 3936272

Please sign in to comment.