issues: 369751771
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
369751771 | MDU6SXNzdWUzNjk3NTE3NzE= | 2484 | Enable add/sub operations involving a CFTimeIndex and a TimedeltaIndex | 6628425 | closed | 0 | 1 | 2018-10-13T01:00:28Z | 2018-10-17T04:00:57Z | 2018-10-17T04:00:57Z | MEMBER | ``` In [1]: import xarray as xr In [2]: start_dates = xr.cftime_range('1999-12', periods=12, freq='M') In [3]: end_dates = start_dates.shift(1, 'M') In [4]: end_dates - start_datesTypeError Traceback (most recent call last) <ipython-input-4-43c24409020b> in <module>() ----> 1 end_dates - start_dates /Users/spencerclark/xarray-dev/xarray/xarray/coding/cftimeindex.pyc in sub(self, other) 365 366 def sub(self, other): --> 367 return CFTimeIndex(np.array(self) - other) 368 369 TypeError: unsupported operand type(s) for -: 'numpy.ndarray' and 'CFTimeIndex' ``` Problem descriptionSubtracting one DatetimeIndex from another produces a TimedeltaIndex: ``` In [5]: import pandas as pd In [6]: start_dates = pd.date_range('1999-12', periods=12, freq='M') In [7]: end_dates = start_dates.shift(1, 'M') In [8]: end_dates - start_dates Out[8]: TimedeltaIndex(['31 days', '29 days', '31 days', '30 days', '31 days', '30 days', '31 days', '31 days', '30 days', '31 days', '30 days', '31 days'], dtype='timedelta64[ns]', freq=None) ``` This should also be straightforward to enable for CFTimeIndexes and would be useful, for example, in the problem described in https://github.com/pydata/xarray/issues/2481#issue-369639339. Expected Output``` In [1]: import xarray as xr In [2]: start_dates = xr.cftime_range('1999-12', periods=12, freq='M') In [3]: end_dates = start_dates.shift(1, 'M') In [4]: end_dates - start_dates Out[4]: TimedeltaIndex(['31 days', '29 days', '31 days', '30 days', '31 days', '30 days', '31 days', '31 days', '30 days', '31 days', '30 days', '31 days'], dtype='timedelta64[ns]', freq=None) ``` |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/2484/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |