Skip to content

Commit adbd59a

Browse files
djhoeseshoyer
authored andcommitted
Fix 'to_masked_array' computing dask arrays twice (#3006)
1 parent fa55060 commit adbd59a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

xarray/core/dataarray.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,8 +1748,9 @@ def to_masked_array(self, copy=True):
17481748
result : MaskedArray
17491749
Masked where invalid values (nan or inf) occur.
17501750
"""
1751-
isnull = pd.isnull(self.values)
1752-
return np.ma.MaskedArray(data=self.values, mask=isnull, copy=copy)
1751+
values = self.values # only compute lazy arrays once
1752+
isnull = pd.isnull(values)
1753+
return np.ma.MaskedArray(data=values, mask=isnull, copy=copy)
17531754

17541755
def to_netcdf(self, *args, **kwargs):
17551756
"""Write DataArray contents to a netCDF file.

0 commit comments

Comments
 (0)