Skip to content

Commit

Permalink
Handle printing bounds of long time interval coords (SciTools#3140)
Browse files Browse the repository at this point in the history
* Handle printing time bounds

* Whatsnew, whitespace fix for test result
  • Loading branch information
DPeterK authored and znicholls committed Jun 15, 2019
1 parent f85edbb commit 06748a6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
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 @@ -782,7 +782,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 @@ -677,13 +677,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

0 comments on commit 06748a6

Please sign in to comment.