Skip to content

Commit

Permalink
Merge 0.18.2 hotfix into master (#5349)
Browse files Browse the repository at this point in the history
* Revert "Use _unstack_once for valid dask and sparse versions (#5315)"

This reverts commit 9165c26.

* 0.18.2 release notes
  • Loading branch information
max-sixty authored May 19, 2021
1 parent 5a602cd commit f58e76c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
10 changes: 8 additions & 2 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ What's New
np.random.seed(123456)
.. _whats-new.0.18.2:
.. _whats-new.0.18.3:

v0.18.2 (unreleased)
v0.18.3 (unreleased)
---------------------

New Features
Expand All @@ -42,6 +42,12 @@ Documentation
Internal Changes
~~~~~~~~~~~~~~~~

.. _whats-new.0.18.2:

v0.18.2 (19 May 2021)
---------------------

This release reverts a regression in xarray's unstacking of dask-backed arrays.
.. _whats-new.0.18.1:

v0.18.1 (18 May 2021)
Expand Down
46 changes: 29 additions & 17 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
)
from .missing import get_clean_interp_index
from .options import OPTIONS, _get_keep_attrs
from .pycompat import dask_version, is_duck_dask_array
from .pycompat import is_duck_dask_array, sparse_array_type
from .utils import (
Default,
Frozen,
Expand Down Expand Up @@ -4028,24 +4028,36 @@ def unstack(

result = self.copy(deep=False)
for dim in dims:
if not sparse and all(
# Dask arrays recently supports assignment by index,
# https://github.com/dask/dask/pull/7393
dask_version >= "2021.04.0" and is_duck_dask_array(v.data)
# Numpy arrays handles the fast path:
or isinstance(v.data, np.ndarray)
for v in self.variables.values()

if (
# Dask arrays don't support assignment by index, which the fast unstack
# function requires.
# https://github.com/pydata/xarray/pull/4746#issuecomment-753282125
any(is_duck_dask_array(v.data) for v in self.variables.values())
# Sparse doesn't currently support (though we could special-case
# it)
# https://github.com/pydata/sparse/issues/422
or any(
isinstance(v.data, sparse_array_type)
for v in self.variables.values()
)
or sparse
# Until https://github.com/pydata/xarray/pull/4751 is resolved,
# we check explicitly whether it's a numpy array. Once that is
# resolved, explicitly exclude pint arrays.
# # pint doesn't implement `np.full_like` in a way that's
# # currently compatible.
# # https://github.com/pydata/xarray/pull/4746#issuecomment-753425173
# # or any(
# # isinstance(v.data, pint_array_type) for v in self.variables.values()
# # )
or any(
not isinstance(v.data, np.ndarray) for v in self.variables.values()
)
):
# Fast unstacking path:
result = result._unstack_once(dim, fill_value)
else:
# Slower unstacking path, examples of array types that
# currently has to use this path:
# * sparse doesn't support item assigment,
# https://github.com/pydata/sparse/issues/114
# * pint has some circular import issues,
# https://github.com/pydata/xarray/pull/4751
result = result._unstack_full_reindex(dim, fill_value, sparse)
else:
result = result._unstack_once(dim, fill_value)
return result

def update(self, other: "CoercibleMapping") -> "Dataset":
Expand Down

0 comments on commit f58e76c

Please sign in to comment.