Skip to content

Commit c370297

Browse files
authored
Fix upcoming sparse change - squash warnings on init errors (#396)
1 parent 83ab848 commit c370297

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ What's new
55
------------------
66
* Fix ESMpy memory issues by explictly freeing the Grid memory upon garbage collection of ``Regridder`` objects. By `Pascal Bourgault <https://github.com/aulemahal>`_.
77
* Address deprecation for xarray 2024.10 in the parallel weight generation. By `Pascal Bourgault <https://github.com/aulemahal>`_.
8+
* 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 <https://github.com/aulemahal>`_.
89

910
0.8.7 (2024-07-16)
1011
------------------

xesmf/frontend.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,9 @@ def _format_xroutput(self, out, new_dims=None):
11121112
def __del__(self):
11131113
# Memory leak issue when regridding over a large number of datasets with xESMF
11141114
# https://github.com/JiaweiZhuang/xESMF/issues/53
1115-
self.grid_in.destroy()
1116-
self.grid_out.destroy()
1115+
if hasattr(self, 'grid_in'): # If the init has failed, grid_in isn't there
1116+
self.grid_in.destroy()
1117+
self.grid_out.destroy()
11171118

11181119

11191120
class SpatialAverager(BaseRegridder):
@@ -1324,7 +1325,10 @@ def _compute_weights(self):
13241325
w_int, area_int = self._compute_weights_and_area(mesh_int)
13251326

13261327
# Append weights from holes as negative weights
1327-
w = xr.concat((w, -w_int), 'out_dim')
1328+
# In sparse >= 0.16, a fill_value of -0.0 is different from 0.0 and the concat would fail
1329+
inv_w_int = -w_int
1330+
inv_w_int.data.fill_value = 0.0
1331+
w = xr.concat((w, inv_w_int), 'out_dim')
13281332

13291333
# Append areas
13301334
area = np.concatenate([area, area_int])
@@ -1382,5 +1386,6 @@ def _format_xroutput(self, out, new_dims=None):
13821386
def __del__(self):
13831387
# Memory leak issue when regridding over a large number of datasets with xESMF
13841388
# https://github.com/JiaweiZhuang/xESMF/issues/53
1385-
self.grid_in.destroy()
1386-
self.grid_out.destroy()
1389+
if hasattr(self, 'grid_in'): # If the init has failed, grid_in isn't there
1390+
self.grid_in.destroy()
1391+
self.grid_out.destroy()

0 commit comments

Comments
 (0)