-
Notifications
You must be signed in to change notification settings - Fork 126
Description
Describe the bug
Calling rolling_filter with window=1 returns an empty DataArray instead of the original data unchanged. A window of 1 is a valid no-op filter and should return the input data as-is. No error or warning is raised, so the data loss is silent.
To Reproduce
import xarray as xr
import numpy as np
from movement.filtering import rolling_filter
data = xr.DataArray(np.random.rand(10), dims=["time"], coords={"time": np.arange(10)})
result = rolling_filter(data, window=1)
print(result.sizes) # Frozen({'time': 0})
print(result.values) # []Expected behaviour
rolling_filter(data, window=1) should return the original data unchanged. A window of 1 means no smoothing is applied.
Suggested fix
Add a guard before the trim step (or even better, at the very beginning of the function to avoid unnecessary processing):
if window == 1:
return dataRoot cause: When window=1, half_window = window // 2 = 0. The trim step calls isel(time=slice(0, -0)) which is equivalent to slice(0, 0) in Python — returning an empty array instead of the full data.
Log file
N/A
Screenshots
N/A
Computer used:
- OS: Linux (Ubuntu)
- Version: 22.04
- Hardware specs: N/A
Additional context
This can silently break downstream trajectory metric computations if a user passes window=1 as a smoke test or minimal smoothing step before calling functions like compute_turning_angle.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status