Lazy SUM with 1D weights sometimes fails
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
Research direction
Start at iris/analysis/init.py, especially lazy_aggregate and _lazy_sum, then run the provided Dask-backed reproduction. Done means collapsing the cube with iris.analysis.SUM and 1D weights completes without the broadcasting error and preserves the expected result.
Written by the indexing model from the issue text.
Description
🐛 Bug Report
Collapsing a cube with lazy data using iris.analysis.SUM and 1D weights
cube = cube.collapsed('a', iris.analysis.SUM, weights=[0, 1])
sometimes fails due to broadcasting errors:
Traceback (most recent call last):
File "/home/b/b309141/scripts/iris/cube_weights.py", line 24, in <module>
cube = cube.collapsed('a', iris.analysis.SUM, weights=[0, 1])
File "/work/bd0854/b309141/mambaforge/envs/esm/lib/python3.10/site-packages/iris/cube.py", line 3785, in collapsed
data_result = aggregator.lazy_aggregate(
File "/work/bd0854/b309141/mambaforge/envs/esm/lib/python3.10/site-packages/iris/analysis/__init__.py", line 545, in lazy_aggregate
return self.lazy_func(data, axis=axis, **kwargs)
File "/work/bd0854/b309141/mambaforge/envs/esm/lib/python3.10/site-packages/iris/analysis/__init__.py", line 1136, in inner_stat
dask_result = dask_stats_function(array, axis=axis, **kwargs)
File "/work/bd0854/b309141/mambaforge/envs/esm/lib/python3.10/site-packages/iris/analysis/__init__.py", line 1136, in inner_stat
dask_result = dask_stats_function(array, axis=axis, **kwargs)
File "/work/bd0854/b309141/mambaforge/envs/esm/lib/python3.10/site-packages/iris/analysis/__init__.py", line 1408, in _lazy_sum
wsum = da.sum(weights_in * array, **kwargs)
File "/work/bd0854/b309141/mambaforge/envs/esm/lib/python3.10/site-packages/dask/array/core.py", line 223, in wrapper
return f(self, other)
File "/work/bd0854/b309141/mambaforge/envs/esm/lib/python3.10/site-packages/dask/array/core.py", line 2349, in __rmul__
return elemwise(operator.mul, other, self)
File "/work/bd0854/b309141/mambaforge/envs/esm/lib/python3.10/site-packages/dask/array/core.py", line 4762, in elemwise
broadcast_shapes(*shapes)
File "/work/bd0854/b309141/mambaforge/envs/esm/lib/python3.10/site-packages/dask/array/core.py", line 4690, in broadcast_shapes
raise ValueError(
ValueError: operands could not be broadcast together with shapes (2,) (2, 3)
How To Reproduce
import dask.array as da
import iris
print("iris version:", iris.__version__)
print()
from iris.coords import AuxCoord
from iris.cube import Cube
aux_coord = AuxCoord([1, 2], var_name='a')
cube = Cube(da.arange(2 * 3).reshape(2, 3), aux_coords_and_dims=[(aux_coord, 0)])
cube = cube.collapsed('a', iris.analysis.SUM, weights=[0, 1])
Expected behaviour
No fail.
Environment
- OS & Version: Red Hat Enterprise Linux 8.5 (Ootpa)
- Iris Version: Tested with 3.2.1 and 3.5.0.dev3, so I guess versions in between are also affected
- Dominant language
- Python
- Stars
- 724
- Forks
- 317
- Avg merge
- 3d 20h
- Merged PRs (30d)
- 9
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from SciTools/iris
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100