diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index a492635dc67..6491bcc1b4a 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -1748,8 +1748,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.