From c7a81b98bc556569a15ce01aedbd8524ccc06c08 Mon Sep 17 00:00:00 2001 From: David Hoese Date: Sun, 9 Jun 2019 20:30:42 -0500 Subject: [PATCH] Fix 'to_masked_array' computing dask arrays twice --- xarray/core/dataarray.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index cab5612dfe1..ce92641203d 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -1746,8 +1746,9 @@ def to_masked_array(self, copy=True): result : MaskedArray Masked where invalid values (nan or inf) occur. """ - isnull = pd.isnull(self.values) - return np.ma.MaskedArray(data=self.values, mask=isnull, copy=copy) + values = self.values # only compute lazy arrays once + isnull = pd.isnull(values) + return np.ma.MaskedArray(data=values, mask=isnull, copy=copy) def to_netcdf(self, *args, **kwargs): """Write DataArray contents to a netCDF file.