diff --git a/CHANGES.rst b/CHANGES.rst index adfcc0d..25490c1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,7 @@ What's new ------------------ * Fix ESMpy memory issues by explictly freeing the Grid memory upon garbage collection of ``Regridder`` objects. By `Pascal Bourgault `_. * Address deprecation for xarray 2024.10 in the parallel weight generation. By `Pascal Bourgault `_. +* Address an upcoming change in sparse 0.16 where COO fill values will distinguish between 0.0 and -0.0. This issue would affect spatial averaging over polygons with holes. By `Pascal Bourgault `_. 0.8.7 (2024-07-16) ------------------ diff --git a/xesmf/frontend.py b/xesmf/frontend.py index b6e88ca..b308947 100644 --- a/xesmf/frontend.py +++ b/xesmf/frontend.py @@ -1112,8 +1112,9 @@ def _format_xroutput(self, out, new_dims=None): def __del__(self): # Memory leak issue when regridding over a large number of datasets with xESMF # https://github.com/JiaweiZhuang/xESMF/issues/53 - self.grid_in.destroy() - self.grid_out.destroy() + if hasattr(self, 'grid_in'): # If the init has failed, grid_in isn't there + self.grid_in.destroy() + self.grid_out.destroy() class SpatialAverager(BaseRegridder): @@ -1324,7 +1325,10 @@ def _compute_weights(self): w_int, area_int = self._compute_weights_and_area(mesh_int) # Append weights from holes as negative weights - w = xr.concat((w, -w_int), 'out_dim') + # In sparse >= 0.16, a fill_value of -0.0 is different from 0.0 and the concat would fail + inv_w_int = -w_int + inv_w_int.data.fill_value = 0.0 + w = xr.concat((w, inv_w_int), 'out_dim') # Append areas area = np.concatenate([area, area_int]) @@ -1382,5 +1386,6 @@ def _format_xroutput(self, out, new_dims=None): def __del__(self): # Memory leak issue when regridding over a large number of datasets with xESMF # https://github.com/JiaweiZhuang/xESMF/issues/53 - self.grid_in.destroy() - self.grid_out.destroy() + if hasattr(self, 'grid_in'): # If the init has failed, grid_in isn't there + self.grid_in.destroy() + self.grid_out.destroy()