-
Notifications
You must be signed in to change notification settings - Fork 298
Closed
Labels
Description
🐛 Bug Report
Iris fails to load some netCDF files due to a malformed cell_method attribute, but is throwing a slightly unhelpful error:
File /opt/scitools/conda/deployments/default-2024_02_20/lib/python3.11/site-packages/iris/fileformats/_nc_load_rules/helpers.py:267, in _split_cell_methods(nc_cell_methods)
265 for ii in range(len(name_start_inds) - 1):
266 method_indices.append((name_start_inds[ii], name_start_inds[ii + 1]))
--> 267 method_indices.append((name_start_inds[-1], len(nc_cell_methods)))
269 # Index the string and match against each substring
270 nc_cell_methods_matches = []
IndexError: list index out of rangeInspection of the stack trace reveals it was failing to correctly match the cell_method attribute value because it was missing a space after the colon separator, i.e.
cell_methods = "time:point"
rather than:
cell_methods = "time: point"
This should probably raise a Warning that the cell_method could not be parsed and continue loading the cube.
How To Reproduce
Steps to reproduce the behaviour:
- Create a netCDF file where a variable has the following attribute (no space after colon):
cell_methods = "time:point" - Load using
iris.load_cube(nc_filename)
Throws error IndexError: list index out of range with stack trace shown above in description.
Expected behaviour
Cube should be loaded but with a Warning stating the cell_method attribute could not be parsed.
Environment
- Linux; RHEL7.9
- 3.2.0.dev978