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/2244#issuecomment-399406545,https://api.github.com/repos/pydata/xarray/issues/2244,399406545,MDEyOklzc3VlQ29tbWVudDM5OTQwNjU0NQ==,6628425,2018-06-22T11:05:18Z,2018-06-22T11:05:18Z,MEMBER,"@aidanheerdegen thanks, I agree an implementation of `shift` would be nice. In the meantime, if the offset can be written as a fixed amount of time (like 365 days as opposed to something like one month), a slightly simpler way than looping over the elements of the index is to add a `datetime.timedelta` object to it, e.g.:
```
In [1]: import numpy as np
In [2]: import xarray as xr
In [3]: from cftime import num2date
In [4]: from datetime import timedelta
In [5]: xr.set_options(enable_cftimeindex=True)
Out[5]:
In [6]: times = num2date(np.arange(730), calendar='noleap', units='days since 0001-01-01')
In [7]: da = xr.DataArray(np.arange(730), coords=[times], dims=['time'])
In [8]: da.time.get_index('time')
Out[8]:
CFTimeIndex([0001-01-01 00:00:00, 0001-01-02 00:00:00, 0001-01-03 00:00:00,
0001-01-04 00:00:00, 0001-01-05 00:00:00, 0001-01-06 00:00:00,
0001-01-07 00:00:00, 0001-01-08 00:00:00, 0001-01-09 00:00:00,
0001-01-10 00:00:00,
...
0002-12-22 00:00:00, 0002-12-23 00:00:00, 0002-12-24 00:00:00,
0002-12-25 00:00:00, 0002-12-26 00:00:00, 0002-12-27 00:00:00,
0002-12-28 00:00:00, 0002-12-29 00:00:00, 0002-12-30 00:00:00,
0002-12-31 00:00:00],
dtype='object', name=u'time', length=730)
In [9]: da.time.get_index('time') + timedelta(days=365)
Out[9]:
Index([0002-01-01 00:00:00, 0002-01-02 00:00:00, 0002-01-03 00:00:00,
0002-01-04 00:00:00, 0002-01-05 00:00:00, 0002-01-06 00:00:00,
0002-01-07 00:00:00, 0002-01-08 00:00:00, 0002-01-09 00:00:00,
0002-01-10 00:00:00,
...
0003-12-22 00:00:00, 0003-12-23 00:00:00, 0003-12-24 00:00:00,
0003-12-25 00:00:00, 0003-12-26 00:00:00, 0003-12-27 00:00:00,
0003-12-28 00:00:00, 0003-12-29 00:00:00, 0003-12-30 00:00:00,
0003-12-31 00:00:00],
dtype='object', length=730)
```
Note, however, that currently the index type is not preserved under this sort of arithmetic (which we might consider a separate issue). This can be alleviated by casting the result as a `CFTimeIndex`:
```
In [10]: xr.CFTimeIndex(da.time.get_index('time') + timedelta(days=365))
Out[10]:
CFTimeIndex([0002-01-01 00:00:00, 0002-01-02 00:00:00, 0002-01-03 00:00:00,
0002-01-04 00:00:00, 0002-01-05 00:00:00, 0002-01-06 00:00:00,
0002-01-07 00:00:00, 0002-01-08 00:00:00, 0002-01-09 00:00:00,
0002-01-10 00:00:00,
...
0003-12-22 00:00:00, 0003-12-23 00:00:00, 0003-12-24 00:00:00,
0003-12-25 00:00:00, 0003-12-26 00:00:00, 0003-12-27 00:00:00,
0003-12-28 00:00:00, 0003-12-29 00:00:00, 0003-12-30 00:00:00,
0003-12-31 00:00:00],
dtype='object', length=730)
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,334778045