Skip to content

Commit 6baca76

Browse files
berkgevecijourdain
authored andcommitted
perf: skip fill value scan and copy for variables without fill values
Only copy and scan for fill values when the variable actually has a _FillValue attribute. Most variables default to NaN, making the comparison a no-op that still scans the entire array. Variables without fill values now return a zero-copy view from reshape.
1 parent 1cd54b9 commit 6baca76

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/e3sm_quickview/plugins/eam_reader.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,10 @@ def _load_variable(self, vardata, varmeta):
423423
slice_tuple.append(self._slices.get(dim, 0))
424424

425425
# Get data with proper slicing
426-
data = vardata[varmeta.name][tuple(slice_tuple)].data.reshape(-1).copy()
427-
data[data == varmeta.fillval] = np.nan
426+
data = vardata[varmeta.name][tuple(slice_tuple)].data.reshape(-1)
427+
if not np.isnan(varmeta.fillval):
428+
data = data.copy()
429+
data[data == varmeta.fillval] = np.nan
428430
return data
429431
except Exception as e:
430432
print_error(f"Error loading variable {varmeta.name}: {e}")

0 commit comments

Comments
 (0)