Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map_blocks: allow user function to add new unindexed dimension. #3817

Merged
merged 2 commits into from
Mar 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ New Features
often means a user is attempting to pass multiple dimensions to group over
and should instead pass a list.
By `Maximilian Roos <https://github.com/max-sixty>`_
- :py:func:`map_blocks` can now apply functions that add new unindexed dimensions.
By `Deepak Cherian <https://github.com/dcherian>`_
- The new ``Dataset._repr_html_`` and ``DataArray._repr_html_`` (introduced
in 0.14.1) is now on by default. To disable, use
``xarray.set_options(display_style="text")``.
Expand All @@ -51,7 +53,6 @@ New Features
(:issue:`3843`, :pull:`3844`)
By `Aaron Spring <https://github.com/aaronspring>`_.


Bug fixes
~~~~~~~~~
- Fix :py:meth:`Dataset.interp` when indexing array shares coordinates with the
Expand Down
3 changes: 3 additions & 0 deletions xarray/core/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ def _wrapper(func, obj, to_array, args, kwargs):
var_chunks.append(input_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