Skip to content

Commit b33aded

Browse files
committed
Also special case pint
1 parent 1c150fc commit b33aded

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

xarray/core/dataset.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
)
8282
from .missing import get_clean_interp_index
8383
from .options import OPTIONS, _get_keep_attrs
84-
from .pycompat import is_duck_dask_array, sparse_array_type
84+
from .pycompat import is_duck_dask_array, pint_array_type, sparse_array_type
8585
from .utils import (
8686
Default,
8787
Frozen,
@@ -3849,6 +3849,12 @@ def unstack(
38493849
or sparse
38503850
# numpy full_like only added `shape` in 1.17
38513851
or LooseVersion(np.__version__) < LooseVersion("1.17")
3852+
# pint doesn't implement `np.full_like` in a way that's
3853+
# currently compatible.
3854+
# https://github.com/pydata/xarray/pull/4746#issuecomment-753425173
3855+
or any(
3856+
isinstance(v.data, pint_array_type) for v in self.variables.values()
3857+
)
38523858
):
38533859
result = result._unstack_full_reindex(dim, fill_value, sparse)
38543860
else:

xarray/core/pycompat.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,10 @@ def is_duck_dask_array(x):
3535
cupy_array_type = (cupy.ndarray,)
3636
except ImportError: # pragma: no cover
3737
cupy_array_type = ()
38+
39+
try:
40+
import pint
41+
42+
pint_array_type = (pint.Quantity,)
43+
except ImportError: # pragma: no cover
44+
pint_array_type = ()

0 commit comments

Comments
 (0)