Skip to content
forked from pydata/xarray

Commit

Permalink
Allow user function to add new unindexed dimension.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcherian committed Mar 2, 2020
1 parent 1f14b11 commit 045ae2b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions xarray/core/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ def _wrapper(func, obj, to_array, args, kwargs, expected_shapes):
var_chunks.append(output_chunks[dim])
elif dim in indexes:
var_chunks.append((len(indexes[dim]),))
elif dim in template.dims:
# new unindexed dimension
var_chunks.append((template.sizes[dim],))

data = dask.array.Array(
hlg, name=gname_l, chunks=var_chunks, dtype=template[name].dtype
Expand Down
2 changes: 2 additions & 0 deletions xarray/tests/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,7 @@ def test_map_blocks_to_array(map_ds):
lambda x: x.to_dataset(),
lambda x: x.drop_vars("x"),
lambda x: x.expand_dims(k=[1, 2, 3]),
lambda x: x.expand_dims(k=3),
lambda x: x.assign_coords(new_coord=("y", x.y * 2)),
lambda x: x.astype(np.int32),
# TODO: [lambda x: x.isel(x=1).drop_vars("x"), map_da],
Expand All @@ -1167,6 +1168,7 @@ def test_map_blocks_da_transformations(func, map_da):
lambda x: x.drop_vars("a"),
lambda x: x.drop_vars("x"),
lambda x: x.expand_dims(k=[1, 2, 3]),
lambda x: x.expand_dims(k=3),
lambda x: x.rename({"a": "new1", "b": "new2"}),
# TODO: [lambda x: x.isel(x=1)],
],
Expand Down

0 comments on commit 045ae2b

Please sign in to comment.