Skip to content

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

Merged
merged 1 commit into from
Feb 27, 2019
Merged

Fix cftime gt 101 #3259

merged 1 commit into from
Feb 27, 2019

Conversation

pp-mo
Copy link
Member

@pp-mo pp-mo commented Feb 4, 2019

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

@SciTools-assistant SciTools-assistant added the Blocked: CLA needed See https://scitools.org.uk. Submit the form at: https://scitools.org.uk/cla/v4/form label Feb 4, 2019
@pp-mo pp-mo changed the base branch from v2.2.x to master February 4, 2019 11:08
@SciTools-assistant SciTools-assistant removed the Blocked: CLA needed See https://scitools.org.uk. Submit the form at: https://scitools.org.uk/cla/v4/form label Feb 4, 2019
This was referenced Feb 5, 2019
Copy link
Member

@lbdreyer lbdreyer left a 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.
Copy link
Member

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

Copy link
Member Author

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

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?

Copy link
Member Author

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

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):
Copy link
Member

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?

Copy link
Member Author

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

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)?

Copy link
Member Author

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

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

Copy link
Member Author

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

Copy link
Member Author

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.

@pp-mo
Copy link
Member Author

pp-mo commented Feb 21, 2019

Thanks for your engagement @lbdreyer
I think you also suggested that this should target v2.2.x ?
I'd like to resolve the issues you've raised first though.

@pp-mo
Copy link
Member Author

pp-mo commented Feb 21, 2019

Hi @lbdreyer hope this addresses the outstanding.
I added a testcase for 'not dropping the time-of-day'.

@lbdreyer lbdreyer added this to the v2.2.1 milestone Feb 22, 2019
@lbdreyer
Copy link
Member

Should this not target the 2.2.x branch?

@pp-mo pp-mo changed the base branch from master to v2.2.x February 25, 2019 17:39
@SciTools-assistant SciTools-assistant added the Blocked: CLA needed See https://scitools.org.uk. Submit the form at: https://scitools.org.uk/cla/v4/form label Feb 25, 2019
@pp-mo pp-mo force-pushed the fix_cftime_gt_101 branch from 8c479a3 to 57ed1e7 Compare February 25, 2019 18:08
@SciTools-assistant SciTools-assistant removed the Blocked: CLA needed See https://scitools.org.uk. Submit the form at: https://scitools.org.uk/cla/v4/form label Feb 25, 2019
@pp-mo
Copy link
Member Author

pp-mo commented Feb 25, 2019

@lbdreyer Should this not target the 2.2.x branch?

Ok, now re-targetted.
N.B.

  • Note : This ALSO unpins cftime
  • Note : This now tests against cf-units rather than cf_units (old name no longer updated), which is like this change, now on master

@@ -5,8 +5,8 @@

cartopy
#conda: proj4<5
cf-units>=2
cftime==1.0.1
cf_units>=2
Copy link
Member

@lbdreyer lbdreyer Feb 26, 2019

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

Copy link
Member

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

Copy link
Member Author

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 !

@pp-mo pp-mo force-pushed the fix_cftime_gt_101 branch from 57ed1e7 to 3e0672f Compare February 26, 2019 17:51
@pp-mo
Copy link
Member Author

pp-mo commented Feb 26, 2019

@lbdreyer undo the change to cf-units?

👍 I have force-pushed again, to avoid confusion when we merge back later

@lbdreyer lbdreyer merged commit b7cd98a into SciTools:v2.2.x Feb 27, 2019
lbdreyer pushed a commit to lbdreyer/iris that referenced this pull request May 28, 2019
lbdreyer pushed a commit to lbdreyer/iris that referenced this pull request Jun 3, 2019
lbdreyer pushed a commit to lbdreyer/iris that referenced this pull request Jun 3, 2019
@pp-mo pp-mo deleted the fix_cftime_gt_101 branch October 17, 2019 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants