issue_comments: 424395224
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/pydata/xarray/issues/2437#issuecomment-424395224 | https://api.github.com/repos/pydata/xarray/issues/2437 | 424395224 | MDEyOklzc3VlQ29tbWVudDQyNDM5NTIyNA== | 6628425 | 2018-09-25T15:41:49Z | 2018-09-25T15:41:49Z | MEMBER | @sbiner these are all reasonable points of confusion. The current behavior in xarray regarding non-standard calendars is complicated, and we are working toward improving the situation. I've tried to provide a recommended solution based on your example as well as some historical/future context. Apologies for the long-winded answer! RecommendationFor accurate round-tripping of date types, I would recommend that you run your code to open the dataset with the xarray option In [2]: import numpy as np In [3]: import xarray as xr In [4]: units = 'days since 2000-02-25' In [5]: times = cftime.num2date(np.arange(7), units=units, calendar='365_day') In [6]: da = xr.DataArray(np.arange(7), coords=[times], dims=['time'], name='a') In [7]: da.to_netcdf('data-noleap.nc') In [8]: with xr.set_options(enable_cftimeindex=True):
...: cftimeindex_enabled = xr.open_dataset('data-noleap.nc')
...:
In [10]: cftimeindex_enabled.time[0]
Out[10]:
<xarray.DataArray 'time' ()>
array(cftime._cftime.DatetimeNoLeap(2000, 2, 25, 0, 0, 0, 0, 6, 56), dtype=object)
Coordinates:
time object 2000-02-25 00:00:00
Default behaviorThe default behavior can be traced back to the early days of xarray (see the original discussion in #118, #121, and #126). It boils down to coercing any dates decoded into The advantage of the default approach is that, when possible, it allows you to take advantage of all the nice features that a time coordinate indexed by a Connecting back to your example, we can see that if we don't open the dataset with In [13]: default.indexes['time'] Out[13]: DatetimeIndex(['2000-02-25', '2000-02-26', '2000-02-27', '2000-02-28', '2000-03-01', '2000-03-02', '2000-03-03'], dtype='datetime64[ns]', name=u'time', freq=None) In [14]: default.time[0]
Out[14]:
<xarray.DataArray 'time' ()>
array(951436800000000000L, dtype='datetime64[ns]')
Coordinates:
time datetime64[ns] 2000-02-25
Future behaviorIn xarray we are slowly working towards better support for operations involving The two major outstanding issues on this front are probably:
- Adding resample functionality to CFTimeIndex (#2191)
- Plotting data with Once those two remaining issues are addressed, one should be able to do most of the significant things one can do with |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
363326726 |