Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cftime/_cftime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import numpy as np
import math
import numpy
import re
import sys
import time
from datetime import datetime as real_datetime
from datetime import timedelta, MINYEAR
Expand Down Expand Up @@ -1615,7 +1616,17 @@ Gregorial calendar.
raise TypeError("cannot compare {0!r} and {1!r} (different calendars)".format(self, other))
return PyObject_RichCompare(dt.to_tuple(), to_tuple(other), op)
else:
raise TypeError("cannot compare {0!r} and {1!r}".format(self, other))
# With Python3 we can use "return NotImplemented". If the other
# object does not have rich comparison instructions for cftime
# then a TypeError is automatically raised. With Python2 in this
# scenario the default behaviour is to compare the object ids
# which will always have a result. Therefore there is no way to
# differentiate between objects that do or do not have legitimate
# comparisons, and so we cannot remove the TypeError below.
if sys.version_info[0] < 3:
raise TypeError("cannot compare {0!r} and {1!r}".format(self, other))
else:
return NotImplemented

cdef _getstate(self):
return (self.year, self.month, self.day, self.hour,
Expand Down