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

Ensure dates are rounded to nearest second #66

Merged
merged 5 commits into from
Sep 15, 2016

Conversation

djkirkham
Copy link
Contributor

Ensures num2date returns datetimes rounded to one second. Allowing microsecond precision introduces rounding errors.

@coveralls
Copy link

coveralls commented Sep 12, 2016

Coverage Status

Coverage increased (+0.08%) to 89.724% when pulling 5924e09 on djkirkham:num2date-rounding into bd72437 on SciTools:master.

# versions of netcdftime that didn't have microsecond precision. In those
# versions, a half-second value would be rounded up or down arbitrarily. It
# is probably not possible to replicate that behaviour with the current
# version (1.4.1), if one wished to do so for the sake of consistency.
Copy link
Member

Choose a reason for hiding this comment

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

Out of interest, why has this been provided as a multi-line comment rather than a docstring?

Copy link
Contributor Author

@djkirkham djkirkham Sep 12, 2016

Choose a reason for hiding this comment

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

This is just a comment for developers, so I don't think it should go in a docstring. I can provide a docstring based on L760-761 if you like, although this is a private function.

@coveralls
Copy link

coveralls commented Sep 12, 2016

Coverage Status

Coverage increased (+0.08%) to 89.724% when pulling 85a4f4f on djkirkham:num2date-rounding into bd72437 on SciTools:master.

@coveralls
Copy link

coveralls commented Sep 12, 2016

Coverage Status

Coverage increased (+0.08%) to 89.724% when pulling 85a4f4f on djkirkham:num2date-rounding into bd72437 on SciTools:master.

@djkirkham
Copy link
Contributor Author

Hmm... previously the num2date functions would have worked when passing a list of values, but after my change they no longer do. It's not in the docstring, but I think I should make it work again. Should I change the doctring while I'm at it?

@DPeterK
Copy link
Member

DPeterK commented Sep 12, 2016

Should I change the doctring

Explicit is good 👍

@DPeterK
Copy link
Member

DPeterK commented Sep 12, 2016

Have you investigated whether you need to do the same for date2num? That is, has the accuracy of that function also been affected by the microseconds change?

@marqh
Copy link
Member

marqh commented Sep 12, 2016

I support this in principal.

I wonder whether we want to publicise this functionality and whether we want to enable access to microseconds

@djkirkham do you feel that implementing such changes would be simply additive, from the changes posted here?

@djkirkham
Copy link
Contributor Author

@dkillick Good point. I hadn't looked into it, and it turns out that behaviour has changed. In the older version of netcdftime it seems date2num discards the microsecond component, but now it doesn't. I suppose we should make changes to keep this behaviour too.

@djkirkham
Copy link
Contributor Author

@marqh

I wonder whether we want to publicise this functionality

Do you mean the functionality of being able to pass a list as argument?

do you feel that implementing such changes would be simply additive, from the changes posted here?

It should be simple to add an optional argument to keep the microseconds

@DPeterK
Copy link
Member

DPeterK commented Sep 13, 2016

I suppose we should make changes to keep this behaviour too.

We should indeed! And we should add a test that proves that the behaviour is correct, given that it's slipped through up to now.

@djkirkham
Copy link
Contributor Author

Actually I'm not sure about including microseconds, since they're not available in the older version of netcdftime. Should this be included as a note in the docstring? What should happen if the user requests microseconds when using the older version? Raise an exception? Ignore it and return seconds resolution?

@marqh
Copy link
Member

marqh commented Sep 13, 2016

Actually I'm not sure about including microseconds, since they're not available in the older version of netcdftime. Should this be included as a note in the docstring? What should happen if the user requests microseconds when using the older version? Raise an exception? Ignore it and return seconds resolution?

This is a good point.

for now, I suggest we maintain the current behaviour, which explicitly ignores microseconds for all versions on netcdf4-python (this PR, as I understand it)

Changes to include these, to provide options to functions and to provide public access to private functions are easy to add at a later date

@DPeterK
Copy link
Member

DPeterK commented Sep 13, 2016

for now, I suggest we maintain the current behaviour

I agree. Banking this will be an excellent step forward and then we can take the time to think about the more complicated questions that @djkirkham raised.

@coveralls
Copy link

coveralls commented Sep 14, 2016

Coverage Status

Coverage increased (+1.0%) to 90.611% when pulling a7018a1 on djkirkham:num2date-rounding into bd72437 on SciTools:master.



def _num2date_to_nearest_second(time_value, utime):
# Return datetime encoding of numeric time value with respect to the given
Copy link
Member

Choose a reason for hiding this comment

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

please make this a docstring

@coveralls
Copy link

coveralls commented Sep 14, 2016

Coverage Status

Coverage increased (+0.9%) to 90.569% when pulling 0f19ad1 on djkirkham:num2date-rounding into bd72437 on SciTools:master.

@coveralls
Copy link

coveralls commented Sep 14, 2016

Coverage Status

Coverage increased (+0.9%) to 90.541% when pulling 00297eb on djkirkham:num2date-rounding into bd72437 on SciTools:master.

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