From c5be03eb1c0c6ba3b4e9db020d1ec54c15f18f3c Mon Sep 17 00:00:00 2001 From: Peter Killick Date: Wed, 3 Oct 2018 13:15:13 +0100 Subject: [PATCH] Handle printing bounds of long time interval coords (#3140) * Handle printing time bounds * Whatsnew, whitespace fix for test result --- ...Aug-20_print-long-time-interval-bounds.txt | 2 ++ lib/iris/coords.py | 6 +++++- lib/iris/tests/unit/coords/test_Coord.py | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 docs/iris/src/whatsnew/contributions_2.2.0/bugfix_2018-Aug-20_print-long-time-interval-bounds.txt 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 42882fbc2c..6402e73263 100644 --- a/lib/iris/coords.py +++ b/lib/iris/coords.py @@ -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()) diff --git a/lib/iris/tests/unit/coords/test_Coord.py b/lib/iris/tests/unit/coords/test_Coord.py index 8cf79caad3..27b468044d 100644 --- a/lib/iris/tests/unit/coords/test_Coord.py +++ b/lib/iris/tests/unit/coords/test_Coord.py @@ -677,6 +677,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') @@ -684,6 +695,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)