issues: 339215679
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
339215679 | MDU6SXNzdWUzMzkyMTU2Nzk= | 2272 | [bug ] xarry np.timedelta64 overflow | 12111171 | closed | 0 | 0 | 2018-07-08T10:43:47Z | 2018-10-28T00:38:59Z | 2018-10-28T00:38:59Z | NONE | ```python import numpy as np import xarray as xr ds = xr.Dataset(coords={'time': ( 'time', np.arange(106300.5, 106665.5+5*365, 365), {'units': 'days since 1800-01-01 00:00:00'})}) ds = xr.decode_cf(ds) ds.to_netcdf('./test.nc') ds = xr.open_dataset('./test.nc', decode_cf=False) print(ds.time) <xarray.DataArray 'time' (time: 6)> array([ 106300.5 , 106665.5 , -106473.482335, -106108.482335, -105743.482335, -105378.482335]) Coordinates: * time (time) float64 1.063e+05 1.067e+05 -1.065e+05 -1.061e+05 ... Attributes: _FillValue: nan units: days since 1800-01-01 calendar: proleptic_gregorian ``` Problem descriptionThe saved netCDF file contains negative time values since "292 years is the maximum length of time a np.timedelta64 object with nanosecond precision can represent" (see here in the documentation) and it therefore runs into an overflow in the example (via skcs explanation to my question on StackOverflow). Expected OutputCorrect time values. Possible solution:For dates outside of the ```python import numpy as np import xarray as xr ds = xr.Dataset(coords={'time': ( 'time', np.arange(106300.5, 106665.5+5*365, 365), {'units': 'days since 0001-01-01 00:00:00'})}) ds = xr.decode_cf(ds) /opt/anaconda2/envs/py36/lib/python3.6/site-packages/xarray/coding/times.py:132: SerializationWarning: Unable to decode time axis into full numpy.datetime64 objects, continuing using dummy cftime.datetime objects instead, reason: dates out of range enable_cftimeindex) /opt/anaconda2/envs/py36/lib/python3.6/site-packages/xarray/coding/variables.py:66: SerializationWarning: Unable to decode time axis into full numpy.datetime64 objects, continuing using dummy cftime.datetime objects instead, reason: dates out of range return self.func(self.array[key]) ds.to_netcdf('./test.nc') ds = xr.open_dataset('./test.nc', decode_cf=False) print(ds.time) <xarray.DataArray 'time' (time: 6)> array([106300.5, 106665.5, 107030.5, 107395.5, 107760.5, 108125.5]) Coordinates: * time (time) float64 1.063e+05 1.067e+05 1.07e+05 1.074e+05 1.078e+05 ... Attributes: _FillValue: nan units: days since 0001-01-01 calendar: gregorian ``` Output of
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/2272/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |