Skip to content

Commit b9974b4

Browse files
committed
Be more clever about scalar broadcasting
1 parent da95bc4 commit b9974b4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

xarray/core/parallel.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ def subset_dataset_to_block(
450450
coords = []
451451

452452
chunk_tuple = tuple(chunk_index.values())
453+
chunk_dims_set = set(chunk_index)
453454
for name, variable in dataset.variables.items():
454455
# make a task that creates tuple of (dims, chunk)
455456
if dask.is_dask_collection(variable.data):
@@ -472,15 +473,17 @@ def subset_dataset_to_block(
472473
for dim in variable.dims
473474
}
474475
subset = variable.isel(subsetter)
475-
if name in chunk_index:
476+
if set(variable.dims) < chunk_dims_set:
476477
# We are including a dimension coordinate,
477478
# minimize duplication by not copying it in the graph for every chunk.
478-
this_var_chunk_tuple = (chunk_index[name],)
479+
this_var_chunk_tuple = tuple(
480+
chunk_index[dim] for dim in variable.dims
481+
)
479482
else:
480483
this_var_chunk_tuple = chunk_tuple
481484

482485
chunk_variable_task = (
483-
f"{name}-{gname}-{dask.base.tokenize(subset)}",
486+
f"{name}-{gname}-{dask.base.tokenize(subsetter)}",
484487
) + this_var_chunk_tuple
485488
if chunk_variable_task not in graph:
486489
graph[chunk_variable_task] = (

0 commit comments

Comments
 (0)