Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading error message from Cube.coord #4898

Closed
rcomer opened this issue Aug 9, 2022 · 2 comments · Fixed by #4928
Closed

Misleading error message from Cube.coord #4898

rcomer opened this issue Aug 9, 2022 · 2 comments · Fixed by #4928
Assignees

Comments

@rcomer
Copy link
Member

rcomer commented Aug 9, 2022

🐛 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
@stephenworsley
Copy link
Contributor

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.

@pp-mo
Copy link
Member

pp-mo commented Aug 24, 2022

I've put up a very simple PR

I.E. #4928

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants