home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 429497014

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/2481#issuecomment-429497014 https://api.github.com/repos/pydata/xarray/issues/2481 429497014 MDEyOklzc3VlQ29tbWVudDQyOTQ5NzAxNA== 6628425 2018-10-13T00:42:35Z 2018-10-13T00:42:35Z MEMBER

I think this would be a fair amount of work to implement :), but in principle it would be a natural step forward in the pattern we have been following in porting time series functionality from pandas for use with calendars supported by cftime.

In the short term, at least for the use-case you describe above, I think a potentially simpler option would be to use a call to CFTimeIndex.shift; based on your example I'll illustrate with the DatetimeIndex version, since resample doesn't exist yet for a CFTimeIndex: ``` In [1]: import xarray as xr; import pandas as pd

In [2]: times = pd.date_range('2000', periods=361)

In [3]: da = xr.DataArray(range(361), [('time', times)])

In [4]: monthly_count = da.resample(time='M').count()

In [5]: end_time = monthly_count.indexes['time']

In [6]: start_time = end_time.shift(-1, 'M')

In [7]: expected_days_in_group = end_time - start_time

In [8]: expected_days_in_group 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]', name=u'time', freq=None) Note that currently subtracting one CFTimeIndex from another (analogous to `end_time - start_time` in the example above) raises an error (I think it should also return a TimedeltaIndex), but that's probably a straightforward fix (I'll create a separate issue): In [8]: a = xr.cftime_range('2000', periods=12, freq='M')

In [9]: b = a.shift(-1, 'M')

In [10]: a - b

TypeError Traceback (most recent call last) <ipython-input-10-09bd029d0285> in <module>() ----> 1 a - b

/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' ```


As a side note, support even for standard PeriodIndexes in xarray needs some work -- see the following existing open issues: #1270, #1565. Serialization to netCDF files would also be nice to support (but I don't see an existing issue for that). I'm sure work to fix these issues would also be appreciated!

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  369639339
Powered by Datasette · Queries took 0.616ms · About: xarray-datasette