-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gracefully handle long time intervals #72
Conversation
Note that as part of this change I've modified how |
cf_units/__init__.py
Outdated
""" | ||
Defines whether this unit describes a time unit with a long time | ||
interval ("months" or "years"). These long time intervals *are* | ||
supported by `UDUNITS2` by are not supported by `netcdftime`. This |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: These long time intervals are supported by UDUNITS2
but are not supported by netcdftime
.
Thanks @lbdreyer - I've corrected the typo. Any more for any more? |
And now the license headers tests fail... |
I'm happy with the implementation + tests. Thanks @dkillick ! |
@dkillick - sorry to drag this back up, but did you raise this with the netcdftime repository? Seems like a thing they may be interested in addressing there... |
@pelson I did not - I should. We should also try and get the associated Iris PR SciTools/iris#2354 merged, a job which is a bit overdue... Edit: note that merging the above-linked still requires a release of cf_units. |
cf_units 1.2.0 has the magic. 👍 |
There's an odd discrepancy between
UDUNITS2
, which will handle months and years as valid time intervals, andnetcdftime
, which won't. This means you can produce a valid time unit with a time interval of years, which you then cannot convert between dates and numbers.This PR adds a new method
is_long_time_interval
to theUnit
class -- does this unit instance describe a time unit with a long interval (that is, months or years)? If it does and it is used in a date <--> number conversion then the unit will raise an exception, rather than the error being raised in the depths ofnetcdftime
.Downstream, the above discrepancy affects Iris coord printing. If the
__str__
method of a coord is called and the coord is a time coord, then the__str__
will try and produce pretty time coord usingnum2date
, which will error, causing the somewhat horrid situation of a print statement causing an exception.