Skip to content

Commit f83f2df

Browse files
committed
Fix ESMF file loading by forcing netCDF4 engine for .nc files
Resolves scipy netCDF reader IndexError when reading ESMF files. The scipy reader fails on certain netCDF files with 'index 0 is out of bounds' error. Force netCDF4 engine for .nc files to ensure robust file reading across all platforms. Fixes: - test/io/test_esmf.py::test_read_esmf - test/io/test_io_common.py::TestIOCommon::test_return_type[grid_from_format4]
1 parent 8449148 commit f83f2df

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

uxarray/core/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ def open_grid(
107107

108108
else:
109109
# Attempt to use Xarray directly for remaining input types
110+
# Force netCDF4 engine for .nc files to avoid scipy reader issues
111+
if isinstance(grid_filename_or_obj, (str, os.PathLike)) and str(grid_filename_or_obj).endswith('.nc'):
112+
kwargs.setdefault('engine', 'netcdf4')
110113
grid_ds = xr.open_dataset(grid_filename_or_obj, chunks=grid_chunks, **kwargs)
111114
grid = Grid.from_dataset(grid_ds, use_dual=use_dual)
112115

0 commit comments

Comments
 (0)