Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 54 additions & 12 deletions lib/iris/_representation/cube_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"""Provides objects describing cube summaries."""
import re

import numpy as np

import iris._lazy_data as _lazy
from iris.common.metadata import hexdigest
import iris.util

Expand Down Expand Up @@ -148,32 +151,71 @@ def __init__(self, cube, coord):
self.unit = ""
else:
self.unit = " {!s}".format(coord.units)
coord_cell = coord.cell(0)
if isinstance(coord_cell.point, str):

# Don't print values of lazy coords, as computing them could cost a lot.
safe_to_print = not _lazy.is_lazy_data(coord.core_points())
if not safe_to_print:
# However there is a special case: If it is a *factory* coord, then those
# are generally lazy. If all the dependencies are real, then it is useful
# (and safe) to compute + print the value.
for factory in cube._aux_factories:
# Note : a factory doesn't have a ".metadata" which can be matched
# against a coord. For now, just assume that it has a 'standard_name'
# property (also not actually guaranteed), and require them to match.
if coord.standard_name == factory.standard_name:
all_deps_real = True
for dependency_coord in factory.dependencies.values():
if (
dependency_coord.has_lazy_points()
or dependency_coord.has_lazy_bounds()
):
all_deps_real = False

if all_deps_real:
safe_to_print = True

if safe_to_print:
coord_cell = coord.cell(0)
else:
coord_cell = None

if coord.dtype.type is np.str_:
self.string_type = True
# 'lines' is value split on '\n', and _each one_ length-clipped.
self.lines = [
iris.util.clip_string(str(item))
for item in coord_cell.point.split("\n")
]
if coord_cell is not None:
# 'lines' is value split on '\n', and _each one_ length-clipped.
self.lines = [
iris.util.clip_string(str(item))
for item in coord_cell.point.split("\n")
]
# 'content' contains a one-line printable version of the string,
content = string_repr(coord_cell.point)
content = iris.util.clip_string(content)
else:
content = "<lazy>"
self.lines = [content]
self.point = None
self.bound = None
# 'content' contains a one-line printable version of the string,
content = string_repr(coord_cell.point)
content = iris.util.clip_string(content)
self.content = content
else:
self.string_type = False
self.lines = None
self.point = "{!s}".format(coord_cell.point)
coord_cell_cbound = coord_cell.bound
coord_cell_cbound = None
if coord_cell is not None:
self.point = "{!s}".format(coord_cell.point)
coord_cell_cbound = coord_cell.bound
else:
self.point = "<lazy>"

if coord_cell_cbound is not None:
self.bound = "({})".format(
", ".join(str(val) for val in coord_cell_cbound)
)
self.content = "{}{}, bound={}{}".format(
self.point, self.unit, self.bound, self.unit
)
elif coord.has_bounds():
self.bound = "+bound"
self.content = "{}{}".format(self.point, self.bound)
else:
self.bound = None
self.content = "{}{}".format(self.point, self.unit)
Expand Down
Loading