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.