Skip to content

Misleading error message from Cube.coord #4898

@rcomer

Description

@rcomer

🐛 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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions