Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Fixed a bug that prevented printing time coordinates with bounds when the time
coordinate was measured on a long interval (that is, ``months`` or ``years``).
6 changes: 5 additions & 1 deletion lib/iris/coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,11 @@ def __str__(self):
points = self._str_dates(self.points)
bounds = ''
if self.has_bounds():
bounds = ', bounds=' + self._str_dates(self.bounds)
if self.units.is_long_time_interval():
bounds_vals = self.bounds
else:
bounds_vals = self._str_dates(self.bounds)
bounds = ', bounds={vals}'.format(vals=bounds_vals)
result = fmt.format(self=self, cls=type(self).__name__,
points=points, bounds=bounds,
other_metadata=self._repr_other_metadata())
Expand Down
20 changes: 20 additions & 0 deletions lib/iris/tests/unit/coords/test_Coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,33 @@ def test_short_time_interval(self):
result = coord.__str__()
self.assertEqual(expected, result)

def test_short_time_interval__bounded(self):
coord = DimCoord([5, 6], standard_name='time',
units='days since 1970-01-01')
coord.guess_bounds()
expected = ("DimCoord([1970-01-06 00:00:00, 1970-01-07 00:00:00], "
"bounds=[[1970-01-05 12:00:00, 1970-01-06 12:00:00],\n"
" [1970-01-06 12:00:00, 1970-01-07 12:00:00]], "
"standard_name='time', calendar='gregorian')")
result = coord.__str__()
self.assertEqual(expected, result)

def test_long_time_interval(self):
coord = DimCoord([5], standard_name='time',
units='years since 1970-01-01')
expected = "DimCoord([5], standard_name='time', calendar='gregorian')"
result = coord.__str__()
self.assertEqual(expected, result)

def test_long_time_interval__bounded(self):
coord = DimCoord([5, 6], standard_name='time',
units='years since 1970-01-01')
coord.guess_bounds()
expected = ("DimCoord([5 6], bounds=[[4.5 5.5]\n [5.5 6.5]], "
"standard_name='time', calendar='gregorian')")
result = coord.__str__()
self.assertEqual(expected, result)

def test_non_time_unit(self):
coord = DimCoord([1.])
expected = repr(coord)
Expand Down