Skip to content

Cubes with long-named Ancillary-Variables or Cell-Measures won't print out #4123

@pp-mo

Description

@pp-mo

🐛 Bug Report

Cubes with too-long names of Ancillary Variables or Cell-measures can't be printed

How To Reproduce

Steps to reproduce the behaviour:

>>> cube = Cube(np.zeros((20,20,20)))
>>> cube.add_ancillary_variable(AncillaryVariable(np.zeros(20), long_name='ancil'), 0)
>>> cube.add_cell_measure(CellMeasure(np.zeros(20), long_name='cellm'), 1)
>>> print(cube)
unknown / (unknown)                 (-- : 20; -- : 20; -- : 20)
     Cell measures:
          cellm                         -        x        -
     Ancillary variables:
          ancil                         x        -        -
>>> cube.cell_measures()[0].rename('rather-overlong-named-cell-measure')
>>> cube
<iris 'Cube' of unknown / (unknown) (-- : 20; -- : 20; -- : 20)>
>>> print(cube)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/h05/itpp/git/iris/iris_main/lib/iris/cube.py", line 2594, in __str__
    return self.summary()
  File "/home/h05/itpp/git/iris/iris_main/lib/iris/cube.py", line 2470, in summary
    cell_measures=vector_cell_measures,
  File "/home/h05/itpp/git/iris/iris_main/lib/iris/cube.py", line 2397, in vector_summary
    pad=" ", width=width, char=char
ValueError: Sign not allowed in string format specifier
>>> cube.cell_measures()[0].rename('cellm')
>>> cube.ancillary_variables()[0].rename('rather-overlong-named-ancillary-variable')
>>> print(cube)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/h05/itpp/git/iris/iris_main/lib/iris/cube.py", line 2594, in __str__
    return self.summary()
  File "/home/h05/itpp/git/iris/iris_main/lib/iris/cube.py", line 2483, in summary
    ancillary_variables=vector_ancillary_variables,
  File "/home/h05/itpp/git/iris/iris_main/lib/iris/cube.py", line 2411, in vector_summary
    pad=" ", width=width, char=char
ValueError: Sign not allowed in string format specifier
>>> 

Expected behaviour

It should extend the dimensions map to accommodate the longest name, as it would do for long-named coords.

Environment

tested with Iris release v3.0.1

Add additional verbose information in a collapsible section.

See here for further details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions