From d269411e044884cf42e622382039b185f1f87db2 Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Fri, 29 Apr 2022 18:49:49 +0100 Subject: [PATCH 1/2] remove ancient workarounds --- lib/iris/coords.py | 25 +----------------- lib/iris/tests/unit/coords/test_Cell.py | 34 +++---------------------- 2 files changed, 4 insertions(+), 55 deletions(-) diff --git a/lib/iris/coords.py b/lib/iris/coords.py index ba0ed8ee5d..bf802b1540 100644 --- a/lib/iris/coords.py +++ b/lib/iris/coords.py @@ -18,7 +18,6 @@ import warnings import zlib -import cftime import dask.array as da import numpy as np import numpy.ma as ma @@ -1411,16 +1410,6 @@ def __common_cmp__(self, other, operator_method): ): raise ValueError("Unexpected operator_method") - # Prevent silent errors resulting from missing cftime - # behaviour. - if isinstance(other, cftime.datetime) or ( - isinstance(self.point, cftime.datetime) - and not isinstance(other, iris.time.PartialDateTime) - ): - raise TypeError( - "Cannot determine the order of " "cftime.datetime objects" - ) - if isinstance(other, Cell): # Cell vs Cell comparison for providing a strict sort order if self.bound is None: @@ -1485,19 +1474,7 @@ def __common_cmp__(self, other, operator_method): else: me = max(self.bound) - # Work around to handle cftime.datetime comparison, which - # doesn't return NotImplemented on failure in some versions of the - # library - try: - result = operator_method(me, other) - except TypeError: - rop = { - operator.lt: operator.gt, - operator.gt: operator.lt, - operator.le: operator.ge, - operator.ge: operator.le, - }[operator_method] - result = rop(other, me) + result = operator_method(me, other) return result diff --git a/lib/iris/tests/unit/coords/test_Cell.py b/lib/iris/tests/unit/coords/test_Cell.py index 650f9ded6c..81370bd0de 100644 --- a/lib/iris/tests/unit/coords/test_Cell.py +++ b/lib/iris/tests/unit/coords/test_Cell.py @@ -30,33 +30,6 @@ def assert_raises_on_comparison(self, cell, other, exception_type, regexp): with self.assertRaisesRegex(exception_type, regexp): cell >= other - def test_cftime_cell(self): - # Check that cell comparison when the cell contains - # cftime.datetime objects raises an exception otherwise - # this will fall back to id comparison producing unreliable - # results. - cell = Cell(cftime.datetime(2010, 3, 21)) - dt = mock.Mock(timetuple=mock.Mock()) - self.assert_raises_on_comparison( - cell, dt, TypeError, "determine the order of cftime" - ) - self.assert_raises_on_comparison( - cell, 23, TypeError, "determine the order of cftime" - ) - self.assert_raises_on_comparison( - cell, "hello", TypeError, "Unexpected type.*str" - ) - - def test_cftime_other(self): - # Check that cell comparison to a cftime.datetime object - # raises an exception otherwise this will fall back to id comparison - # producing unreliable results. - dt = cftime.datetime(2010, 3, 21) - cell = Cell(mock.Mock(timetuple=mock.Mock())) - self.assert_raises_on_comparison( - cell, dt, TypeError, "determine the order of cftime" - ) - def test_PartialDateTime_bounded_cell(self): # Check that bounded comparisions to a PartialDateTime # raise an exception. These are not supported as they @@ -85,10 +58,9 @@ def test_PartialDateTime_unbounded_cell(self): def test_datetime_unbounded_cell(self): # Check that cell comparison works with datetimes. dt = datetime.datetime(2000, 6, 15) - cell = Cell(datetime.datetime(2000, 1, 1)) - # Note the absence of the inverse of these - # e.g. self.assertGreater(dt, cell). - # See http://bugs.python.org/issue8005 + cell = Cell(cftime.datetime(2000, 1, 1)) + self.assertGreater(dt, cell) + self.assertGreaterEqual(dt, cell) self.assertLess(cell, dt) self.assertLessEqual(cell, dt) From 8c01a526f7aca079e4be91d2f08fc0100831a97f Mon Sep 17 00:00:00 2001 From: Ruth Comer Date: Fri, 7 Oct 2022 11:45:09 +0100 Subject: [PATCH 2/2] whatsnew --- docs/src/whatsnew/latest.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index d14d7b2452..f4cd3f44bd 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -60,6 +60,9 @@ This document explains the changes made to Iris for this release variables and cell measures that map to a cube dimension of length 1 are now included in the respective vector sections. (:pull:`4945`) +#. `@rcomer`_ removed some old redundant code that prevented determining the + order of time cells. (:issue:`4697`, :pull:`4729`) + 💣 Incompatible Changes =======================