pydata / pydata/xarray

DataArray.rolling fails with chunk size of 1 or 2 (reemergence of issue #9862)

Open
#10,115 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs triage
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

What happened?

The problem is exactly as written in closed issue #9862, but I'm using:

  • xarray: 2025.1.2
  • dask: 2025.2.0

Since everything is the same (including traceback and behavior when pasted into console or binder), please refer to original issue for complete description.

I didn't click "new issue" since it's an old issue that was closed, but is not fixed.

What did you expect to happen?

We would expect the rolling mean to calculate correctly.

Minimal Complete Verifiable Example
import dask.array as da
import xarray as xr
import numpy as np

# Dimensions and sizes
nx, ny, nt = 100, 200, 50  # size of x, y, and time dimensions
x = np.linspace(0, 10, nx)  # x-coordinates
y = np.linspace(0, 20, ny)  # y-coordinates
time = np.linspace(0, 1, nt)  # time coordinates

# Generate a random Dask array with lazy computation
data = da.random.random(size=(nx, ny, nt), chunks=(100, 200, 1))

# Create an xarray DataArray with coordinates and attributes
data_array = xr.DataArray(
    data,
    dims=["x", "y", "time"],
    coords={"x": x, "y": y, "time": time},
    name="dummy_data",
    attrs={"units": "arbitrary", "description": "Dummy 3D dataset"}
)

d_rolling = data_array.rolling(time=5).mean()
d_rolling.compute()
MVCE confirmation
  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
Traceback (most recent call last):

  Cell In[6], line 24
    d_rolling.compute()

  File /srv/conda/envs/notebook/lib/python3.10/site-packages/xarray/core/dataarray.py:1206 in compute
    return new.load(**kwargs)

  File /srv/conda/envs/notebook/lib/python3.10/site-packages/xarray/core/dataarray.py:1174 in load
    ds = self._to_temp_dataset().load(**kwargs)

  File /srv/conda/envs/notebook/lib/python3.10/site-packages/xarray/core/dataset.py:900 in load
    evaluated_data: tuple[np.ndarray[Any, Any], ...] = chunkmanager.compute(

  File /srv/conda/envs/notebook/lib/python3.10/site-packages/xarray/namedarray/daskmanager.py:85 in compute
    return compute(*data, **kwargs)  # type: ignore[no-untyped-call, no-any-return]

  File /srv/conda/envs/notebook/lib/python3.10/site-packages/dask/base.py:662 in compute
    results = schedule(dsk, keys, **kwargs)

  File /srv/conda/envs/notebook/lib/python3.10/site-packages/dask/_task_spec.py:740 in __call__
    return self.func(*new_argspec, **kwargs)

ValueError: Moving window (=5) must between 1 and 4, inclusive
Anything else we need to know?

No response

Environment
INSTALLED VERSIONS ------------------ commit: None python: 3.10.16 | packaged by conda-forge | (main, Dec 5 2024, 14:16:10) [GCC 13.3.0] python-bits: 64 OS: Linux OS-release: 6.8.0-52-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.14.3 libnetcdf: 4.9.2

xarray: 2025.1.2
pandas: 2.2.3
numpy: 2.1.3
scipy: 1.15.2
netCDF4: 1.7.2
pydap: 3.5.3
h5netcdf: 1.5.0
h5py: 3.13.0
zarr: 2.18.3
cftime: 1.6.4
nc_time_axis: 1.4.1
iris: 3.11.0
bottleneck: 1.4.2
dask: 2025.2.0
distributed: 2025.2.0
matplotlib: 3.10.1
cartopy: 0.24.0
seaborn: 0.13.2
numbagg: 0.9.0
fsspec: 2025.2.0
cupy: None
pint: 0.24.4
sparse: 0.15.5
flox: None
numpy_groupies: None
setuptools: 75.8.0
pip: 25.0
conda: None
pytest: None
mypy: None
IPython: 8.32.0
sphinx: None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction and compare it with closed issue #9862; inspect the xarray/core/dataarray.py and xarray/namedarray/daskmanager.py paths shown in the traceback. Run the DataArray rolling example with chunks of 1 or 2 and confirm rolling(time=5).mean().compute() succeeds without the ValueError.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.