diff --git a/docs/iris/src/whatsnew/contributions_2.2.0/bugfix_2018-Aug-20_print-long-time-interval-bounds.txt b/docs/iris/src/whatsnew/contributions_2.2.0/bugfix_2018-Aug-20_print-long-time-interval-bounds.txt new file mode 100644 index 0000000000..3651598b72 --- /dev/null +++ b/docs/iris/src/whatsnew/contributions_2.2.0/bugfix_2018-Aug-20_print-long-time-interval-bounds.txt @@ -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``). \ No newline at end of file diff --git a/lib/iris/coords.py b/lib/iris/coords.py index e4a8eb35f2..08f697ae43 100644 --- a/lib/iris/coords.py +++ b/lib/iris/coords.py @@ -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()) diff --git a/lib/iris/tests/unit/coords/test_Coord.py b/lib/iris/tests/unit/coords/test_Coord.py index b43df9447a..e8838d1650 100644 --- a/lib/iris/tests/unit/coords/test_Coord.py +++ b/lib/iris/tests/unit/coords/test_Coord.py @@ -374,6 +374,17 @@ 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') @@ -381,6 +392,15 @@ def test_long_time_interval(self): 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)