Skip to content

Commit

Permalink
Refactor checks to avoid .data more
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Augspurger committed Oct 28, 2021
1 parent bba423f commit 6363a76
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4161,26 +4161,22 @@ def unstack(
nonindexes = [
self.variables[k] for k in set(self.variables) - set(self.xindexes)
]
needs_full_reindex = (
# 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 nonindexes)
# 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 nonindexes)
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 nonindexes)
# Notes for each of these cases:
# 1. Dask arrays don't support assignment by index, which the fast unstack
# function requires.
# https://github.com/pydata/xarray/pull/4746#issuecomment-753282125
# 2. Sparse doesn't currently support (though we could special-case it)
# https://github.com/pydata/sparse/issues/422
# 3. pint requires checking if it's a NumPy array until
# https://github.com/pydata/xarray/pull/4751 is resolved,
# Once that is resolved, explicitly exclude pint arrays.
# pint doesn't implement `np.full_like` in a way that's
# currently compatible.
needs_full_reindex = sparse or any(
is_duck_dask_array(v.data)
or isinstance(v.data, sparse_array_type)
or not isinstance(v.data, np.ndarray)
for v in nonindexes
)

for dim in dims:
Expand Down

0 comments on commit 6363a76

Please sign in to comment.