Skip to content
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

Merged
merged 3 commits into from
Feb 14, 2017

Conversation

DPeterK
Copy link
Member

@DPeterK DPeterK commented Feb 9, 2017

There's an odd discrepancy between UDUNITS2, which will handle months and years as valid time intervals, and netcdftime, 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 the Unit 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 of netcdftime.

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 using num2date, which will error, causing the somewhat horrid situation of a print statement causing an exception.

@DPeterK
Copy link
Member Author

DPeterK commented Feb 9, 2017

Note that as part of this change I've modified how cf_units.num2date and cf_units.date2num function. They now create a cf_units.Unit instance and use that instance to run the conversion so that the new long time interval exception in cf_units is raised and not the exception in netcdftime.

@coveralls
Copy link

coveralls commented Feb 9, 2017

Coverage Status

Coverage increased (+0.1%) to 90.653% when pulling 48bec11 on dkillick:long_time_intervals into 77eac61 on SciTools:master.

"""
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
Copy link
Member

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.

@DPeterK
Copy link
Member Author

DPeterK commented Feb 14, 2017

Thanks @lbdreyer - I've corrected the typo.

Any more for any more?

@DPeterK
Copy link
Member Author

DPeterK commented Feb 14, 2017

And now the license headers tests fail...

@coveralls
Copy link

coveralls commented Feb 14, 2017

Coverage Status

Coverage increased (+0.1%) to 90.653% when pulling 792a523 on dkillick:long_time_intervals into 77eac61 on SciTools:master.

@lbdreyer
Copy link
Member

I'm happy with the implementation + tests. Thanks @dkillick !

@lbdreyer lbdreyer merged commit bd988a4 into SciTools:master Feb 14, 2017
@DPeterK DPeterK deleted the long_time_intervals branch February 28, 2017 15:18
@pelson
Copy link
Member

pelson commented Oct 27, 2017

@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...

@DPeterK
Copy link
Member Author

DPeterK commented Oct 30, 2017

@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.

@pelson
Copy link
Member

pelson commented Jan 11, 2018

Edit: note that merging the above-linked still requires a release of cf_units.

cf_units 1.2.0 has the magic. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants