iris
iris copied to clipboard
Misleading error message from Cube.coord
🐛 Bug Report
I just spent some time, with help from colleagues, trying to figure out why my data didn't have a realization coordinate. It turned out that it did have a realization coordinate, but the error message was misleading.
How To Reproduce
import iris
import iris.coords
import iris.cube
print(f"{iris.__version__=}")
cube = iris.cube.Cube(1)
coord = iris.coords.DimCoord(1, standard_name="realization", units=1)
cube.add_aux_coord(coord.copy())
coord.var_name = "realization" # without this line we get no exception.
cube.coord(coord)
iris.__version__='3.2.1.post0'
Traceback (most recent call last):
File "coord_matching.py", line 14, in <module>
cube.coord(coord)
File "[python-path]/python3.8/site-packages/iris/cube.py", line 1919, in coord
raise iris.exceptions.CoordinateNotFoundError(emsg)
iris.exceptions.CoordinateNotFoundError: "Expected to find exactly 1 'realization' coordinate, but found none."
Expected behaviour
The error message should be clearer about what it is trying to match. Or it should make a more lenient comparison between the coordinates.
Environment
- OS & Version: RHEL7
- Iris Version: 3.2.1.post0
I've put up a very simple PR to make it more obvious that an object is being compared against rather than a string. A more verbose error message could potentially give more detail, but I think it would be a bit more complicated to do so there could be diminishing returns going down that route. Let me know if you think these error messages would have been sufficient.
I've put up a very simple PR
I.E. https://github.com/SciTools/iris/pull/4928