Skip to content

Commit 045ae2b

Browse files
committed
Allow user function to add new unindexed dimension.
1 parent 1f14b11 commit 045ae2b

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

xarray/core/parallel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ def _wrapper(func, obj, to_array, args, kwargs, expected_shapes):
401401
var_chunks.append(output_chunks[dim])
402402
elif dim in indexes:
403403
var_chunks.append((len(indexes[dim]),))
404+
elif dim in template.dims:
405+
# new unindexed dimension
406+
var_chunks.append((template.sizes[dim],))
404407

405408
data = dask.array.Array(
406409
hlg, name=gname_l, chunks=var_chunks, dtype=template[name].dtype

xarray/tests/test_dask.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@ def test_map_blocks_to_array(map_ds):
11471147
lambda x: x.to_dataset(),
11481148
lambda x: x.drop_vars("x"),
11491149
lambda x: x.expand_dims(k=[1, 2, 3]),
1150+
lambda x: x.expand_dims(k=3),
11501151
lambda x: x.assign_coords(new_coord=("y", x.y * 2)),
11511152
lambda x: x.astype(np.int32),
11521153
# TODO: [lambda x: x.isel(x=1).drop_vars("x"), map_da],
@@ -1167,6 +1168,7 @@ def test_map_blocks_da_transformations(func, map_da):
11671168
lambda x: x.drop_vars("a"),
11681169
lambda x: x.drop_vars("x"),
11691170
lambda x: x.expand_dims(k=[1, 2, 3]),
1171+
lambda x: x.expand_dims(k=3),
11701172
lambda x: x.rename({"a": "new1", "b": "new2"}),
11711173
# TODO: [lambda x: x.isel(x=1)],
11721174
],

0 commit comments

Comments
 (0)