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

num2date: return datetimes by default if possible #165

Merged
merged 15 commits into from
May 11, 2021

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented Apr 22, 2021

Aims to fix #161. I don't know how to run the tests (or anything else) locally with my branch, so I am trusting to Travis! I did run flake8 locally on the files I’ve changed, and it only complained about two lines that I haven’t touched.

@rcomer
Copy link
Member Author

rcomer commented Apr 22, 2021

There is Test Carnage, but I'm not (yet) convinced it's because I've done something wrong...

@rcomer
Copy link
Member Author

rcomer commented Apr 23, 2021

Right. The reason my original effort didn't work was because we call cftime.utime.num2date, which doesn't appear to accept the only_use_cftime_datetimes keyword. So I have switched to using the cftime.num2date function.

To do this properly, we should probably sort out #166, but I think that's beyond the scope of this PR.

@rcomer
Copy link
Member Author

rcomer commented Apr 23, 2021

Why are tests not running for my latest commit? 😕

cf_units/__init__.py Outdated Show resolved Hide resolved
cf_units/__init__.py Outdated Show resolved Hide resolved
@rcomer
Copy link
Member Author

rcomer commented Apr 23, 2021

All tests now passing, except for some doctests (and a whole raft of python2.7 tests) which also fail at #164, so not caused by this change.

@coveralls
Copy link

coveralls commented May 10, 2021

Coverage Status

Coverage remained the same at 91.651% when pulling 97bd7f7 on rcomer:datetime-default into 3a85094 on SciTools:master.

@rcomer
Copy link
Member Author

rcomer commented May 10, 2021

Rebased. Tests now all passing 🙂

@trexfeathers
Copy link
Collaborator

Thanks for looking into this @rcomer 💐

Having discussed with a few devs, I don't want to merge this to master:

To avoid future difficulties/irrelevance a package should evolve with its dependencies, so as @duncanwp hinted at it in #161: the next major release of cf-units should explicitly adopt the new default behaviour of cftime.num2date. That's what should be going into master. It would certainly be great to provide the only_use_cftime_datetimes parameter, but again the default value should align with ctime.

Pinning the behaviour to how it was in the 'old world' is a bugfix, enabling continued use of the existing major release of cf-units. As I understand it, bugfix changes can/should only be applied to a bugfix branch, and that certainly seems appropriate here given the conflict with an opposite intended future behaviour.

I'm just making sure I fully understand how this ought to be done. I had started working on a migration to Cirrus+Nox, but at least for now Travis seems to be playing nicely so I'll only involve that if I need to!

@rcomer
Copy link
Member Author

rcomer commented May 10, 2021

Thanks @trexfeathers, I shall await further instructions.

Copy link
Collaborator

@trexfeathers trexfeathers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In terms of the code, this looks good. One change if you can:

Also need an equivalent change when using cftime.utime - L1937, and propagate upwards for the container method and uses.

You're definitely right to move away from using cftime.utime where possible, since it's on its way out. But as of v1.4.1 it's still in the cftime API and it also has a only_use_cftime_datetimes parameter - see here.

@rcomer
Copy link
Member Author

rcomer commented May 10, 2021

@trexfeathers have I understood correctly? If the utime object contains the only_use_cftime_datetimes flag then we don't need the changes to _num2date_to_nearest_second or associated test changes.

Unfortunately, having made and reverted changes to test__num2date_to_nearest_second.py, I have confused the license header checker.

@trexfeathers
Copy link
Collaborator

@trexfeathers have I understood correctly? If the utime object contains the only_use_cftime_datetimes flag then we don't need the changes to _num2date_to_nearest_second or associated test changes.

Oh dear, I was only suggesting an additional change, not undoing your existing! While you are correct, I was trying to say that your changes up to that point had been valuable anyway:

You're definitely right to move away from using cftime.utime where possible, since it's on its way out.

@rcomer
Copy link
Member Author

rcomer commented May 10, 2021

Okedoke. Commit histories are fun!

I believe this shows the changes since your initial review.

Does the utime method need a test? I can't find any existing ones for that method...

@rcomer
Copy link
Member Author

rcomer commented May 10, 2021

Also, do you have a "squash" option in your merge button or should I do that manually?

Copy link
Collaborator

@trexfeathers trexfeathers 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 @rcomer. If you can target the new v2.1.5 branch I'm good to merge.

Does the utime method need a test? I can't find any existing ones for that method...

Since you didn't introduce this method, and given its future limited life in cftime, I'm happy to forego additional tests.

Also, do you have a "squash" option in your merge button or should I do that manually?

I do have the squash option - I just need to remember to use it!

@rcomer rcomer changed the base branch from master to v2.1.5 May 11, 2021 12:03
@rcomer
Copy link
Member Author

rcomer commented May 11, 2021

Thanks @trexfeathers, now re-targetted.

@trexfeathers trexfeathers merged commit 855077c into SciTools:v2.1.5 May 11, 2021
@rcomer rcomer deleted the datetime-default branch May 12, 2021 15:19
rcomer added a commit to rcomer/cf-units that referenced this pull request May 25, 2021
* make proper datetimes default

* replace cftime.utime.num2date with cftime.num2date

* attempt fixes

* pass both utime and Unit to _num2date_to_nearest_second

* revert _num2date_to_nearest_second calling sequence

* dummy commit to kick travis

* appease stickler

* license headers

* contain only_use_cftime_datetimes within utime object

* revert test__num2date_to_nearest_second.py

* actually pass flag to where it is needed

* reinstate type check

* Reinstate _num2date_to_nearest_second changes

This reverts commit 0b89777.

* reinstate test changes

* make sure option is passed down num2date
@rcomer rcomer mentioned this pull request May 25, 2021
trexfeathers pushed a commit that referenced this pull request Jun 8, 2021
* num2date: return datetimes by default if possible (#165)

* make proper datetimes default

* replace cftime.utime.num2date with cftime.num2date

* attempt fixes

* pass both utime and Unit to _num2date_to_nearest_second

* revert _num2date_to_nearest_second calling sequence

* dummy commit to kick travis

* appease stickler

* license headers

* contain only_use_cftime_datetimes within utime object

* revert test__num2date_to_nearest_second.py

* actually pass flag to where it is needed

* reinstate type check

* Reinstate _num2date_to_nearest_second changes

This reverts commit 0b89777.

* reinstate test changes

* make sure option is passed down num2date

* change num2date default to cftime.datetimes

* change num2date tests expected type

* remove utime

* replace cftime julian date functions

* pep8

* update matplotlib comments

* pep8

* specify flag in matplotlib note

* review actions

* update utilities.rst
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.

Change of behaviour due to latest cftime
4 participants