Skip to content

Commit 001c586

Browse files
committed
Fix automatic fill_value being too large when masking ugrid topology variables
1 parent 361cc96 commit 001c586

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/emsarray/conventions/ugrid.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,20 @@ def update_connectivity(
227227
if start_index != 0:
228228
column_values = column_values + start_index
229229

230+
dtype = connectivity.encoding.get('dtype', connectivity.dtype)
231+
232+
if dtype.kind == 'i':
233+
# Ensure the fill value fits within the representable integers
234+
max_representable = np.iinfo(dtype).max
235+
if max_representable < fill_value:
236+
fill_value = max_representable
237+
230238
# We need to preseve the integer dtype,
231239
# while also accounting for masked values.
232240
# xarray does not make this easy.
233241
# By constructing the array using new_fill_value where needed,
234242
# setting the dtype explicitly, and adding the _FillValue attribute,
235243
# xarray will cooperate.
236-
dtype = connectivity.encoding.get('dtype', connectivity.dtype)
237244
include_row = ~np.ma.getmask(row_indices)
238245
raw_values = np.array([
239246
[

0 commit comments

Comments
 (0)