Repository navigation
Closed
Labels
needs attentionIt's been a while since this was pushed on. Needs attention from the owner or a maintainer.needs triageNeeds a response from a contributor
Description
From pydata/xarray#8345
import dask.array
array = dask.array.ones(shape=(2, 1000, 100, 4800), chunks=(2, 1000, 100, 83))
with dask.config.set({'array.slicing.split_large_chunks': True}):
array = array.reshape(2, 1000, 100, 4, 1200)
array---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[16], line 3
1 array = dask.array.ones(shape=(2, 1000, 100, 4800), chunks=(2, 1000, 100, 83))
2 with dask.config.set({'array.slicing.split_large_chunks': True}):
----> 3 array = array.reshape(2, 1000, 100, 4, 1200)
4 array
File ~/miniforge3/envs/xarray-release/lib/python3.11/site-packages/dask/array/core.py:2219, in Array.reshape(self, merge_chunks, limit, *shape)
2217 if len(shape) == 1 and not isinstance(shape[0], Number):
2218 shape = shape[0]
-> 2219 return reshape(self, shape, merge_chunks=merge_chunks, limit=limit)
File ~/miniforge3/envs/xarray-release/lib/python3.11/site-packages/dask/array/reshape.py:285, in reshape(x, shape, merge_chunks, limit)
283 else:
284 chunk_plan.append("auto")
--> 285 outchunks = normalize_chunks(
286 chunk_plan,
287 shape=shape,
288 limit=limit,
289 dtype=x.dtype,
290 previous_chunks=inchunks,
291 )
293 x2 = x.rechunk(inchunks)
295 # Construct graph
File ~/miniforge3/envs/xarray-release/lib/python3.11/site-packages/dask/array/core.py:3095, in normalize_chunks(chunks, shape, limit, dtype, previous_chunks)
3092 chunks = tuple("auto" if isinstance(c, str) and c != "auto" else c for c in chunks)
3094 if any(c == "auto" for c in chunks):
-> 3095 chunks = auto_chunks(chunks, shape, limit, dtype, previous_chunks)
3097 if shape is not None:
3098 chunks = tuple(c if c not in {None, -1} else s for c, s in zip(chunks, shape))
File ~/miniforge3/envs/xarray-release/lib/python3.11/site-packages/dask/array/core.py:3218, in auto_chunks(chunks, shape, limit, dtype, previous_chunks)
3212 largest_block = math.prod(
3213 cs if isinstance(cs, Number) else max(cs) for cs in chunks if cs != "auto"
3214 )
3216 if previous_chunks:
3217 # Base ideal ratio on the median chunk size of the previous chunks
-> 3218 result = {a: np.median(previous_chunks[a]) for a in autos}
3220 ideal_shape = []
3221 for i, s in enumerate(shape):
File ~/miniforge3/envs/xarray-release/lib/python3.11/site-packages/dask/array/core.py:3218, in <dictcomp>(.0)
3212 largest_block = math.prod(
3213 cs if isinstance(cs, Number) else max(cs) for cs in chunks if cs != "auto"
3214 )
3216 if previous_chunks:
3217 # Base ideal ratio on the median chunk size of the previous chunks
-> 3218 result = {a: np.median(previous_chunks[a]) for a in autos}
3220 ideal_shape = []
3221 for i, s in enumerate(shape):
IndexError: tuple index out of rangeMetadata
Metadata
Assignees
Labels
needs attentionIt's been a while since this was pushed on. Needs attention from the owner or a maintainer.needs triageNeeds a response from a contributor
Activity
mrocklin commentedon Oct 26, 2023
I'm not personally familiar with this code. Git blame points to @TomAugspurger . Tom, can you help out here?
TomAugspurger commentedon Oct 28, 2023
I'm not too sure either.
I took a quick look and it appears that
auto_chunksimplicitly requires that the length ofchunksandprevious_chunksmatches atdask/dask/array/core.py
Line 3223 in 4884d56
In this case, we're using it as part of a reshape operation that is changing the number of dimensions, so the number of input chunks differs from the number of output chunks.
I'd hoped we could work around it by inserting a dummy dimension at the end, but I didn't have any luck with that. We might need to update
auto_chunksto handle the case where the number of dimensions is changing.dcherian commentedon Oct 29, 2023
Could just skip it, that's better than failing.
schlunma commentedon Feb 27, 2024
I just stumbled across this problem as well. Is there any workaround for this (except for omitting
limit=...inreshape, which creates large chunks)?