From 88eb42e58f5f1442009f04668aed335e1926abf0 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sun, 3 Jan 2021 14:13:18 -0800 Subject: [PATCH] Only run fast unstack on numpy arrays --- xarray/core/dataset.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 6db33a27e9e..0f0308605b8 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -3849,6 +3849,18 @@ def unstack( or sparse # numpy full_like only added `shape` in 1.17 or LooseVersion(np.__version__) < LooseVersion("1.17") + # 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.array) for v in self.variables.values() + ) ): result = result._unstack_full_reindex(dim, fill_value, sparse) else: