Skip to content

Commit

Permalink
Also special case pint
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Jan 2, 2021
1 parent 1c150fc commit b33aded
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
)
from .missing import get_clean_interp_index
from .options import OPTIONS, _get_keep_attrs
from .pycompat import is_duck_dask_array, sparse_array_type
from .pycompat import is_duck_dask_array, pint_array_type, sparse_array_type
from .utils import (
Default,
Frozen,
Expand Down Expand Up @@ -3849,6 +3849,12 @@ def unstack(
or sparse
# numpy full_like only added `shape` in 1.17
or LooseVersion(np.__version__) < LooseVersion("1.17")
# 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()
)
):
result = result._unstack_full_reindex(dim, fill_value, sparse)
else:
Expand Down
7 changes: 7 additions & 0 deletions xarray/core/pycompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@ def is_duck_dask_array(x):
cupy_array_type = (cupy.ndarray,)
except ImportError: # pragma: no cover
cupy_array_type = ()

try:
import pint

pint_array_type = (pint.Quantity,)
except ImportError: # pragma: no cover
pint_array_type = ()

0 comments on commit b33aded

Please sign in to comment.