Skip to content

Commit

Permalink
Merge pull request #131 from Unidata/issue128
Browse files Browse the repository at this point in the history
more informative error message (issue #128)
  • Loading branch information
jswhit authored Oct 26, 2019
2 parents c62a142 + 8fcf732 commit ea68823
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cftime/_cftime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,12 @@ Gregorial calendar.
elif isinstance(other, datetime_python):
# datetime - real_datetime
if not dt.datetime_compatible:
raise ValueError("cannot compute the time difference between dates with different calendars")
msg="""
Cannot compute the time difference between dates with different calendars.
One of the datetime objects may have been converted to a native python
datetime instance. Try using only_use_cftime_datetimes=True when creating the
datetime object."""
raise ValueError(msg)
return dt._to_real_datetime() - other
elif isinstance(other, timedelta):
# datetime - timedelta
Expand All @@ -1379,7 +1384,12 @@ Gregorial calendar.
if isinstance(self, datetime_python):
# real_datetime - datetime
if not other.datetime_compatible:
raise ValueError("cannot compute the time difference between dates with different calendars")
msg="""
Cannot compute the time difference between dates with different calendars.
One of the datetime objects may have been converted to a native python
datetime instance. Try using only_use_cftime_datetimes=True when creating the
datetime object."""
raise ValueError(msg)
return self - other._to_real_datetime()
else:
return NotImplemented
Expand Down

0 comments on commit ea68823

Please sign in to comment.