-
Notifications
You must be signed in to change notification settings - Fork 49
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
Conversation
# 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. |
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.
Out of interest, why has this been provided as a multi-line comment rather than a docstring?
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.
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.
5924e09
to
9b813ba
Compare
9b813ba
to
85a4f4f
Compare
Hmm... previously the |
Explicit is good 👍 |
Have you investigated whether you need to do the same for |
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? |
@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 |
Do you mean the functionality of being able to pass a list as argument?
It should be simple to add an optional argument to keep the microseconds |
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. |
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 |
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. |
|
||
|
||
def _num2date_to_nearest_second(time_value, utime): | ||
# Return datetime encoding of numeric time value with respect to the given |
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.
please make this a docstring
Ensures
num2date
returns datetimes rounded to one second. Allowing microsecond precision introduces rounding errors.