Skip to content

Conversation

stephenworsley
Copy link
Contributor

Fixes the bug with #3351.

Previously, if a cube had an attribute which was a string containing '\n', attempting to get the html_repr of that cube would cause an exception. This pull request would instead add what is in that new line to a new row of the html_repr.
A cube whose string representation looks like:

sea_water_potential_temperature / (degC) (-- : 148; -- : 180)
     Auxiliary coordinates:
          latitude                           x         x
          longitude                          x         x
     Scalar coordinates:
          depth: 4.999938 m, bound=(0.0, 10.0) m
          time: 0001-01-01 12:00:00
     Attributes:
          Conventions: CF-1.5
          history: Wed Jul 10 11:00:19 2019: ncks -A -v LON surface_20150112.nc 1997_mon06.nc4
...
     Cell methods:
          mean: time

will now have a html_repr which creates a table looking something like:

Sea Water Potential Temperature (degC) -- --
Shape 148 180
Auxiliary coordinates
latitude x x
longitude x x
Scalar coordinates
depth 4.999938 m, bound=(0.0, 10.0) m
time 0001-01-01 12:00:00
Attributes
Conventions CF-1.5
history Wed Jul 10 11:00:19 2019: ncks -A -v LON surface_20150112.nc 1997_mon06.nc4
...
Cell methods
mean time

This cube and its representations were created with the following code using attributes taken from #3351:

import iris
from iris.experimental.representation import CubeRepresentation

filepath = iris.sample_data_path('orca2_votemper.nc')
cube = iris.load_cube(filepath)

cube.attributes['history'] = "Wed Jul 10 11:00:19 2019: ncks -A -v LON surface_20150112.nc 1997_mon06.nc4\n "+\
                             "Wed Jul 10 10:51:41 2019: cdo splitmon CNRR-GSISAT_hourly_rain_1997.nc4 1997_mon"

print(str(cube))
rep = CubeRepresentation(cube).repr_html()
print(rep)

@stephenworsley
Copy link
Contributor Author

Alternatively, my new commit adds the new line to the previous cell instead of a new row.
The resulting table would now look like this:

Sea Water Potential Temperature (degC) -- --
Shape 148 180
Auxiliary coordinates
latitude x x
longitude x x
Scalar coordinates
depth 4.999938 m, bound=(0.0, 10.0) m
time 0001-01-01 12:00:00
Attributes
Conventions CF-1.5
history Wed Jul 10 11:00:19 2019: ncks -A -v LON surface_20150112.nc 1997_mon06.nc4
...
Cell methods
mean time

Copy link
Member

@DPeterK DPeterK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephenworsley thanks for getting a fix in place for this annoying bug with the cube html repr! Could I ask you to add a test for this new functionality to Test__make_content please, as well as a new test class in the same test module for the new method you've added? Doesn't have to be anything special, just enough to check it's doing what we want (as well as nothing we don't!). Thanks!

@pp-mo
Copy link
Member

pp-mo commented Sep 6, 2019

add a test for this new functionality to Test__make_content please

Long enough, I think it's good!

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

Successfully merging this pull request may close these issues.

3 participants