home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 334778045

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
334778045 MDU6SXNzdWUzMzQ3NzgwNDU= 2244 Implement shift for CFTimeIndex 6063709 closed 0     3 2018-06-22T07:42:16Z 2018-10-02T14:44:30Z 2018-10-02T14:44:30Z CONTRIBUTOR      

Code Sample

```python import numpy as np import xarray as xr import pandas as pd

from cftime import num2date, DatetimeNoLeap

times = num2date(np.arange(730), calendar='noleap', units='days since 0001-01-01') da = xr.DataArray(np.arange(730), coords=[times], dims=['time']) ```

Problem description

I am trying to shift a time index as I need to align datasets to a common start point.

Directly incrementing one of the CFTimeIndex values works: ```python

da.time.get_index('time')[0] + pd.Timedelta('365 days') cftime.DatetimeNoLeap(2, 1, 1, 0, 0, 0, 0, -1, 1) Trying to use `shift` does not:python da.time.get_index('time').shift(1,'Y') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/g/data3/hh5/public/apps/miniconda3/envs/analysis3-18.04/lib/python3.6/site-packages/pandas/core/indexes/base.py", line 2629, in shift type(self).name) NotImplementedError: Not supported for type CFTimeIndex ```

If I want to shift a time index is the only way currently is to loop over all the individual elements of the index and add a time offset to each.

Expected Output

I would expect to have CFTimeIndex shifted by the desired time delta.

Output of xr.show_versions()

# Paste the output here xr.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 3.6.5.final.0 python-bits: 64 OS: Linux OS-release: 3.10.0-693.17.1.el6.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: C LOCALE: None.None xarray: 0.10.7 pandas: 0.23.1 numpy: 1.14.5 scipy: 1.1.0 netCDF4: 1.3.1 h5netcdf: 0.5.1 h5py: 2.8.0 Nio: None zarr: 2.2.0 bottleneck: 1.2.1 cyordereddict: None dask: 0.17.5 distributed: 1.21.8 matplotlib: 1.5.3 cartopy: 0.16.0 seaborn: 0.8.1 setuptools: 39.2.0 pip: 9.0.3 conda: None pytest: 3.6.1 IPython: 6.4.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/2244/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 3 rows from issue in issue_comments
Powered by Datasette · Queries took 82.564ms · About: xarray-datasette