Skip to content

Commit

Permalink
Fix 'to_masked_array' computing dask arrays twice (#3006)
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese authored and shoyer committed Jun 10, 2019
1 parent fa55060 commit adbd59a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit adbd59a

Please sign in to comment.