-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
cftime.datetime serialization example failing in latest doc build #2127
Comments
I haven't looked into this in detail, but my guess is that this is somehow related to NumPy refusing to convert a timedelta that includes years or months into nanoseconds, because years and months can have different numbers of days. To help debug this, it would be helpful to know exactly what the input |
With the specified |
It's confusing to me, because I don't see where NumPy is getting years or months metadata from the
Unlike
|
This must be a NumPy bug. Here's an even simpler reproduction:
Any other day I've tried works. Also, the following code works (at least on my laptop):
|
Any multiple of 7 days (one week) seems to trigger it, e.g.,
For now, maybe try casting each element individually to
|
Interesting, thanks for investigating things further and confirming that it likely is a NumPy bug. I put up a fix following your suggestion in #2128 and also included a test. |
Huh...my test is still triggering some failures due to this issue in #2128. Oddly on my laptop the original bug doesn't appear to exist if I use python version 3.6.5 and numpy version 1.14.3 (the versions on Travis where I'm getting a failure):
and not surprisingly the test passes:
So it appears to be platform dependent. Trying this out on a linux machine with these versions I can reproduce the issue (which seems to persist even for individual timedeltas, explaining the test failure):
It's not ideal, but should we try to go with pandas to do the type conversion? It seems to work on the linux platform:
|
Yes, let's use |
Awesome, thanks for tracking that down in NumPy so quickly! I updated #2128 accordingly. |
Code Sample, a copy-pastable example if possible
Problem description
This seems to be an edge case that was not covered in the tests I added in #1252. Strangely if I cast the result of
np.unique(np.diff(dates))
as an array before converting to'timedelta64[ns]'
objects things work:Might anyone have any ideas as to what the underlying issue is? The fix could be as simple as that, but I don't understand why that makes a difference.
Expected Output
da.to_netcdf('test.nc')
should succeed without an error.Output of
xr.show_versions()
xarray: 0.8.2+dev641.g7302d7e
pandas: 0.22.0
numpy: 1.13.1
scipy: 0.19.1
netCDF4: 1.3.1
h5netcdf: None
h5py: 2.7.1
Nio: None
zarr: 2.2.0
bottleneck: None
cyordereddict: 1.0.0
dask: 0.17.1
distributed: 1.21.3
matplotlib: 2.2.2
cartopy: None
seaborn: 0.8.1
setuptools: 38.4.0
pip: 9.0.1
conda: None
pytest: 3.3.2
IPython: 5.5.0
sphinx: 1.7.1
The text was updated successfully, but these errors were encountered: