-
Notifications
You must be signed in to change notification settings - Fork 2
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
non-uniform datetime type #292
Comments
I think this could also be considered a bug in |
The fix for the test above only works for the specific dates in the test. 1970-01-01 is special as it is zero for the internal time. If we replace 1970-1980 it by e.g. 1956-1966 the test fails. |
I found the reason for the problem. It's not the time resolution as I first suspected but a coordinate recomputation in
I still think this is very weird behaviour. Maybe I missed a hint when reading the docs. |
I've opened a second issue for the |
I'd push this upstream to xarray. I can't believe this behaviour is intentional |
After thinking a bit about the code in xr.polyfit, I think we should definitely try to move away from nanosecond precision to e.g. hours or minutes. This should improve the accuracy of the fits |
Describe the bug
Depending on the function the format of the returned time coordinates seems to differ. While a dataset created with e.g.
pd.daterange()
has the typenp.datatime64[ns]
, the return value oftest_ts.coords['time'].loc[{'time': [np.datetime64('1970-01-01')]}]
has the datatypenp.datetime64[D]
Failing Test
Below a test I constructed to show the behaviour. It fails because (I think) the internal date conversion of
xr.polyfit
andxr.polyval
use the format of thenp.datetime64
variables to convert the dates to integers used for the actual fitting and evaluation. The example below works if the dates are manually specified as having nanosecond resolution.Expected behavior
It would be good if the date resolution is fixed without having to specify it manually. It would also be good if it's e.g. days and not nanoseconds (but not necessary unless nanoseconds has a negative impact on the fits)
System (please complete the following information):
Linux mint 22
Additional context
In the filling strategy code I'm currently writing I use nanosecond for now, because that seems to be the default behaviour of
pd.date_range
. But apr.loc[{'time': ['1999-01-01]}]
gives days back, so it's not a general solution to just be specific in the new code.The text was updated successfully, but these errors were encountered: