Skip to content

Commit e1eb82b

Browse files
aulemahalRaphael Dussin
authored andcommitted
Fix upcoming sparse change - squash warnings on init errors (#396)
1 parent b6b12c8 commit e1eb82b

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
@@ -1117,8 +1117,9 @@ def _format_xroutput(self, out, new_dims=None):
11171117
def __del__(self):
11181118
# Memory leak issue when regridding over a large number of datasets with xESMF
11191119
# https://github.com/JiaweiZhuang/xESMF/issues/53
1120-
self.grid_in.destroy()
1121-
self.grid_out.destroy()
1120+
if hasattr(self, 'grid_in'): # If the init has failed, grid_in isn't there
1121+
self.grid_in.destroy()
1122+
self.grid_out.destroy()
11221123

11231124

11241125
class SpatialAverager(BaseRegridder):
@@ -1329,7 +1330,10 @@ def _compute_weights(self):
13291330
w_int, area_int = self._compute_weights_and_area(mesh_int)
13301331

13311332
# Append weights from holes as negative weights
1332-
w = xr.concat((w, -w_int), 'out_dim')
1333+
# In sparse >= 0.16, a fill_value of -0.0 is different from 0.0 and the concat would fail
1334+
inv_w_int = -w_int
1335+
inv_w_int.data.fill_value = 0.0
1336+
w = xr.concat((w, inv_w_int), 'out_dim')
13331337

13341338
# Append areas
13351339
area = np.concatenate([area, area_int])
@@ -1387,5 +1391,6 @@ def _format_xroutput(self, out, new_dims=None):
13871391
def __del__(self):
13881392
# Memory leak issue when regridding over a large number of datasets with xESMF
13891393
# https://github.com/JiaweiZhuang/xESMF/issues/53
1390-
self.grid_in.destroy()
1391-
self.grid_out.destroy()
1394+
if hasattr(self, 'grid_in'): # If the init has failed, grid_in isn't there
1395+
self.grid_in.destroy()
1396+
self.grid_out.destroy()

0 commit comments

Comments
 (0)