Skip to content
2 changes: 2 additions & 0 deletions movement/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def rolling_filter(
is sufficient to compute the result.

"""
if window == 1:
return data
half_window = window // 2
data_windows = data.pad( # Pad the edges to avoid NaNs
time=half_window, mode="reflect"
Expand Down
13 changes: 13 additions & 0 deletions tests/test_unit/test_filtering.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from contextlib import nullcontext as does_not_raise

import numpy as np
import pytest
import xarray as xr

Expand Down Expand Up @@ -279,3 +280,15 @@
n_low_confidence_kpts = 5
assert isinstance(position_filtered, xr.DataArray)
assert n_nans == valid_input_dataset.sizes["space"] * n_low_confidence_kpts


def test_rolling_filter_window_1():
"""window=1 should return data unchanged."""
rng = np.random.default_rng()

Check warning on line 287 in tests/test_unit/test_filtering.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Provide a seed for this random generator.

See more on https://sonarcloud.io/project/issues?id=neuroinformatics-unit_movement&issues=AZzpYwIEtPOaBsa6cQDV&open=AZzpYwIEtPOaBsa6cQDV&pullRequest=888

Check notice

Code scanning / SonarCloud

Results that depend on random number generation should be reproducible Low test

Provide a seed for this random generator. See more on SonarQube Cloud

data = xr.DataArray(
rng.random(10), dims=["time"], coords={"time": np.arange(10)}
)

result = rolling_filter(data, window=1)
xr.testing.assert_equal(result, data)