-
Notifications
You must be signed in to change notification settings - Fork 296
Fix cftime gt 101 #3259
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
Fix cftime gt 101 #3259
Conversation
lib/iris/tests/unit/fileformats/pp_load_rules/test__epoch_date_hours.py
Outdated
Show resolved
Hide resolved
lib/iris/tests/unit/fileformats/pp_load_rules/test__epoch_date_hours.py
Outdated
Show resolved
Hide resolved
lib/iris/tests/unit/fileformats/pp_load_rules/test__epoch_date_hours.py
Outdated
Show resolved
Hide resolved
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.
Looks good @pp-mo !
I agree with the approach: it is best to keep consistent with the old behaviour rather than break compatibility.
I just have a couple of issues relating to the handling of the handling of the time component of the datetime and the years in the copyright message.
Also this PR will need rebasing as it is complaining about the requirements/core.txt file/
# Return an 'hours since epoch' number for a date. | ||
# Also handle dates with a zero year, month or day in a special way : such | ||
# dates were valid inputs for 'date2num' up to cftime version 1.0.1, | ||
# but not since: Results here are consistent with the "old" behaviour. |
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.
Why this style docstring rather than just
def _epoch_date_hours():
"""
Returns ...
""""
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.
Ok. will fix
# lbuser=[0] * 7, lbrsvd=[0] * 4, | ||
# brsvd=[0] * 4, brlev=0, | ||
# core_data=mock_core_data, | ||
# realised_dtype=mock_data.dtype) |
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.
Are you leaving these commented out lines for a specific reason?
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.
No. Oops, will remove !
field._x_coord_name = lambda: 'longitude' | ||
field._y_coord_name = lambda: 'latitude' | ||
field.coord_system = lambda: None | ||
field.configure_mock(**kwargs) |
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.
I definitely prefer approach with adding **kwargs here 👍
# dates were valid inputs for 'date2num' up to cftime version 1.0.1, | ||
# but not since: Results here are consistent with the "old" behaviour. | ||
days_offset = None | ||
if (datetime.year < 1 or datetime.month < 1 or datetime.day < 1): |
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.
Does the pp/ff spec ever allow for these to be negative values?
cftime (1.0.3.4) does allow it:
>>> cftime.datetime(year=-1, month=10, day=3)
cftime._cftime.datetime(-1, 10, 3, 0, 0, 0, 0, -1, 1)
Although I guess it wouldn't matter as they they would still pass straight though as lower down (e.g. line 461) you check y==0
So why do datetime.year < 1
here but y ==0
further down?
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.
Does the pp/ff spec ever allow for these to be negative values?
No, I don't think that can happen.
why do datetime.year < 1 here but y ==0 further down?
I think it was less characters, this just barely fits on one line !!
I will tidy up ...
days_offset += days_in_year_0 | ||
|
||
# Replace with a modified date, that cftime will accept. | ||
datetime = nc_datetime(y, m, d) |
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.
What has happened to the time component of the datetime (i.e. the hour, minute, second)?
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.
Ooh, good spot !! 💐
I will fix.
@@ -0,0 +1,134 @@ | |||
# (C) British Crown Copyright 2014 - 2017, Met Office |
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.
Need to change these years. And it looks you need to update the dates on the other files as well
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.
Ok, will fix.
It's annoying that this test has stopped working in Travis, not sure when that happened but several headers are now out-of-date.
There was also talk of ditching the file headers, or at least the dates, but discussions with internal legal team are not complete AFAIK.
#3272 Attempts to fix ..
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.
Can now wait for #3272, and rebase when that is in.
Thanks for your engagement @lbdreyer |
Hi @lbdreyer hope this addresses the outstanding. |
Should this not target the 2.2.x branch? |
8c479a3
to
57ed1e7
Compare
Ok, now re-targetted.
|
requirements/core.txt
Outdated
@@ -5,8 +5,8 @@ | |||
|
|||
cartopy | |||
#conda: proj4<5 | |||
cf-units>=2 | |||
cftime==1.0.1 | |||
cf_units>=2 |
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.
Can you undo the change to cf-units
?
It would be better to keep the hyphened name
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.
I think this came from it still being cf_units
on master
, as the fix has gone onto the v2.2x
branch which has not yet been mergedback onto master
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.
My mistake, I think I was reading the diffs the wrong way round !
57ed1e7
to
3e0672f
Compare
👍 I have force-pushed again, to avoid confusion when we merge back later |
Hopefully, this fixes test failures resulting from changes in cftime > 1.0.1.
The test problems seem to be confined to the PP/FF loading.
Hence the approach here.
It's still possible that the problem could occur in other areas though.
(Including knock-on problems with other tests, that this will turn up...)
Addresses #3248
Note : This ALSO unpins cftime