-
Notifications
You must be signed in to change notification settings - Fork 300
Closed
Description
📰 Custom Issue
From iris v3, cells for time coordinates now use cftime.datetime objects. These objects cannot be sorted or compared in the guise of coordinate cells, e.g.
import cftime
import iris.coords
t1 = cftime.datetime(2022, 3, 8, 12, 0, 0)
t2 = cftime.datetime(2022, 3, 9, 12, 0, 0)
c1 = iris.coords.Cell(point=t1)
c2 = iris.coords.Cell(point=t2)
cells = [c1, c2]
print(sorted(cells))will fail with the error:
Traceback (most recent call last):
File "./test_time_sort.py", line 19, in <module>
print(sorted(cells))
File "lib/python3.8/site-packages/iris/coords.py", line 1513, in __lt__
return self.__common_cmp__(other, operator.lt)
File "lib/python3.8/site-packages/iris/coords.py", line 1419, in __common_cmp__
"Cannot determine the order of " "cftime.datetime objects"
TypeError: Cannot determine the order of cftime.datetime objects
This protection was probably added to the cells construct at a time when cftime.datatime objects could not be compared, but now they can and as such the protection should be removed, e.g. from the above t1 and t2 can be compared sensibly. I would hope that lines 1413 to 1420 of coords.py can be simply removed. However, a tranche of tests will also likely need to be re-engineered as well.
Metadata
Metadata
Assignees
Labels
No labels