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

Printing similar coordinates when one has numpy array attributes #3921

Closed
rcomer opened this issue Nov 13, 2020 · 2 comments · Fixed by #3922
Closed

Printing similar coordinates when one has numpy array attributes #3921

rcomer opened this issue Nov 13, 2020 · 2 comments · Fixed by #3922
Assignees
Milestone

Comments

@rcomer
Copy link
Member

rcomer commented Nov 13, 2020

🐛 Bug Report

If you print a cube which has two similar coordinates, there is some logic which (as far as I can tell) creates a string to distinguish the two coordinates. This logic fails if one of the coordinates happens to have attributes whose values are numpy arrays.

How To Reproduce

Minimal example:

import iris
import numpy as np

cube = iris.cube.Cube(range(5))
coord1 = iris.coords.DimCoord(
    range(5), long_name='foo', attributes=dict(bar=np.array([7, 42])))
coord2 = coord1.copy()
coord2.units = 'K'

cube.add_dim_coord(coord1, 0)
cube.add_aux_coord(coord2, 0)

print(cube)

Result:

Traceback (most recent call last):
  File "iris3_cube_print_fail.py", line 13, in <module>
    print(cube)
  File "[site-packages-path]/lib/python3.6/site-packages/iris/cube.py", line 2599, in __str__
    return self.summary()
  File "[site-packages-path]/lib/python3.6/site-packages/iris/cube.py", line 2445, in summary
    vector_dim_coords, cube_header, max_line_offset
  File "[site-packages-path]/lib/python3.6/site-packages/iris/cube.py", line 2423, in vector_summary
    vectors, vector_summary, extra_indent
  File "[site-packages-path]/lib/python3.6/site-packages/iris/cube.py", line 2215, in _summary_extra
    extra = self._summary_coord_extra(coord, indent)
  File "[site-packages-path]/lib/python3.6/site-packages/iris/cube.py", line 2198, in _summary_coord_extra
    if attributes.setdefault(key, value) != value:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Expected behaviour

I should be able to print this cube.

Environment

  • OS & Version: RHEL7.9
  • Iris Version: v3 release candidate
@rcomer
Copy link
Member Author

rcomer commented Nov 13, 2020

The error occurs even if the second coordinate has an empty attributes dictionary. Presumably because the first coordinate gets compared to itself in this loop.

@rcomer rcomer self-assigned this Nov 13, 2020
@rcomer rcomer linked a pull request Nov 13, 2020 that will close this issue
@bjlittle bjlittle added this to the v3.1.0 milestone Nov 25, 2020
@rcomer rcomer modified the milestones: v3.1.0, v3.0.0 Nov 25, 2020
@rcomer
Copy link
Member Author

rcomer commented Nov 25, 2020

Closed by #3922. Linked issues don't seem to be closing automatically lately???

@rcomer rcomer closed this as completed Nov 25, 2020
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.

2 participants