Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add support for CFTimeIndex in get_clean_interp_index #3631
Add support for CFTimeIndex in get_clean_interp_index #3631
Changes from 23 commits
d5c2242
77bb24c
03e7769
e169cf4
303020f
210fb94
1cfe72d
4964163
83f6c89
6298953
3d23ccf
2ba1803
9a648d9
e873da2
532756d
73d8729
4288780
077145e
758d81c
d0d8bfe
6c9630a
d18c775
78e17ec
6615c97
2df2b29
31f5417
2974af9
eeb5074
6b9631f
5656fdb
dcf98ff
4842a96
6dbf225
c90dc97
71fb87d
3d9f333
b04785c
d24cae4
6f0c504
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
So the potential for loss of precision is here, but only when
array
comes in with dtypenp.timedelta64[ns]
or finer. I feel like we can guard against this; we could do this in one of two ways:np.timedelta64
arrays.np.timedelta64
arrays more robustly in this function, and name it something that reflects that both standard library timedeltas and NumPy timedeltas can be safely passed to it.I probably prefer (1) as a solution.
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 there are two cases where we're losing precision:
When we discussed about loss of precision, I was more worried about 2 than 1, hence maybe some confusion earlier. I'm concerned 2 will lead to hard to track bugs.
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.
Ah, that makes sense. Indeed I had mainly been thinking about 1. Thanks for the clear example. My apologies for being dense earlier. At least in the short term, I guess I'm still not so worried about 2, primarily because it is already an issue in the existing code (i.e. even for
np.datetime64[ns]
dates). So this update is not changing the behavior materially; it's just extending the approach to allow for long time ranges between cftime dates1.Earlier you raised a good question regarding whether there would be a benefit to keeping these values as integers as long as possible to avoid these floating point problems -- it seems like there could be in the case of
differentiate
andintegrate
-- however, that would probably require some refactoring to do the unit conversion after the operation involving the numeric times, rather than before, to avoid overflow. I'd be open to discussing this more, but I don't feel like it's necessarily a blocker here, unless you have an example that clearly shows otherwise.Regardless, I really appreciate your careful thoughts and help with this. This has been useful discussion.
1I guess it's also important to note that we are currently naively differencing cftime dates to produce timedeltas, which even before float conversion is not microsecond-exact:
We have worked around this before in xarray; see
exact_cftime_datetime_difference
.