home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 388556972

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/pull/1252#issuecomment-388556972 https://api.github.com/repos/pydata/xarray/issues/1252 388556972 MDEyOklzc3VlQ29tbWVudDM4ODU1Njk3Mg== 6628425 2018-05-12T13:56:02Z 2018-05-12T13:56:02Z MEMBER

Thanks @shoyer, those are good questions. I addressed your inline comments. Let me know if you have anything else.

What happens when you try to resample along CFTimeIndex?

Through pandas, this raises an informative TypeError:

``` In [1]: from cftime import num2date

In [2]: import numpy as np

In [3]: import xarray as xr

In [4]: xr.set_options(enable_cftimeindex=True) Out[4]: <xarray.core.options.set_options at 0x10c3a99d0>

In [5]: time = num2date(np.arange(5), units='days since 0001-01-01', calendar='noleap')

In [6]: data = xr.DataArray(np.arange(5), coords=[time], dims=['time'])

In [7]: data.resample(time='2D').mean()

TypeError Traceback (most recent call last) <ipython-input-8-577095ede89a> in <module>() ----> 1 data.resample(time='2D').mean()

/Users/spencerclark/xarray-dev/xarray/xarray/core/common.pyc in resample(self, freq, dim, how, skipna, closed, label, base, keep_attrs, **indexer) 616 resampler = self._resample_cls(self, group=group, dim=dim_name, 617 grouper=grouper, --> 618 resample_dim=RESAMPLE_DIM) 619 620 return resampler

/Users/spencerclark/xarray-dev/xarray/xarray/core/resample.pyc in init(self, args, kwargs) 128 "cannot have the same name as actual dimension " 129 "('{}')! ".format(self._resample_dim, self._dim)) --> 130 super(DataArrayResample, self).init(args, kwargs) 131 132 def apply(self, func, shortcut=False, kwargs):

/Users/spencerclark/xarray-dev/xarray/xarray/core/groupby.pyc in init(self, obj, group, squeeze, grouper, bins, cut_kwargs) 233 raise ValueError('index must be monotonic for resampling') 234 s = pd.Series(np.arange(index.size), index) --> 235 first_items = s.groupby(grouper).first() 236 full_index = first_items.index 237 if first_items.isnull().any():

//anaconda/envs/xarray-dev/lib/python2.7/site-packages/pandas/core/generic.pyc in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, kwargs) 5160 return groupby(self, by=by, axis=axis, level=level, as_index=as_index, 5161 sort=sort, group_keys=group_keys, squeeze=squeeze, -> 5162 kwargs) 5163 5164 def asfreq(self, freq, method=None, how=None, normalize=False,

//anaconda/envs/xarray-dev/lib/python2.7/site-packages/pandas/core/groupby.pyc in groupby(obj, by, kwds) 1846 raise TypeError('invalid type: %s' % type(obj)) 1847 -> 1848 return klass(obj, by, kwds) 1849 1850

//anaconda/envs/xarray-dev/lib/python2.7/site-packages/pandas/core/groupby.pyc in init(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, **kwargs) 514 level=level, 515 sort=sort, --> 516 mutated=self.mutated) 517 518 self.obj = obj

//anaconda/envs/xarray-dev/lib/python2.7/site-packages/pandas/core/groupby.pyc in _get_grouper(obj, key, axis, level, sort, mutated, validate) 2848 # a passed-in Grouper, directly convert 2849 if isinstance(key, Grouper): -> 2850 binner, grouper, obj = key._get_grouper(obj, validate=False) 2851 if key.key is None: 2852 return grouper, [], obj

//anaconda/envs/xarray-dev/lib/python2.7/site-packages/pandas/core/resample.pyc in _get_grouper(self, obj, validate) 1118 def _get_grouper(self, obj, validate=True): 1119 # create the resampler and return our binner -> 1120 r = self._get_resampler(obj) 1121 r._set_binner() 1122 return r.binner, r.grouper, r.obj

//anaconda/envs/xarray-dev/lib/python2.7/site-packages/pandas/core/resample.pyc in _get_resampler(self, obj, kind) 1114 raise TypeError("Only valid with DatetimeIndex, " 1115 "TimedeltaIndex or PeriodIndex, " -> 1116 "but got an instance of %r" % type(ax).name) 1117 1118 def _get_grouper(self, obj, validate=True):

TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'CFTimeIndex' ```

What happens when you try to plot a DataArray with a CFTimeIndex?

I updated things such that if cftime.datetime objects are used as a coordinate when plotting, the error message looks like: ``` In [1]: from cftime import num2date

In [2]: import numpy as np

In [3]: import xarray as xr

In [4]: xr.set_options(enable_cftimeindex=True) Out[4]: <xarray.core.options.set_options at 0x10af58850>

In [5]: time = num2date(np.arange(5), units='days since 0001-01-01', calendar='noleap')

In [6]: data = xr.DataArray(np.arange(5), coords=[time], dims=['time'])

In [7]: data.plot()

TypeError Traceback (most recent call last) <ipython-input-7-118f55e0b3d0> in <module>() ----> 1 data.plot()

/Users/spencerclark/xarray-dev/xarray/xarray/plot/plot.pyc in call(self, kwargs) 357 358 def call(self, kwargs): --> 359 return plot(self._da, **kwargs) 360 361 @functools.wraps(hist)

/Users/spencerclark/xarray-dev/xarray/xarray/plot/plot.pyc in plot(darray, row, col, col_wrap, ax, rtol, subplot_kws, kwargs) 155 kwargs['ax'] = ax 156 --> 157 return plotfunc(darray, kwargs) 158 159

/Users/spencerclark/xarray-dev/xarray/xarray/plot/plot.pyc in line(darray, args, kwargs) 258 yplt = darray.coords[ylabel] 259 --> 260 _ensure_plottable(xplt) 261 262 primitive = ax.plot(xplt, yplt, args, **kwargs)

/Users/spencerclark/xarray-dev/xarray/xarray/plot/plot.pyc in _ensure_plottable(*args) 54 if not (_valid_numpy_subdtype(np.array(x), numpy_types) or 55 _valid_other_type(np.array(x), other_types)): ---> 56 raise TypeError('Plotting requires coordinates to be numeric ' 57 'or dates of type np.datetime64 or ' 58 'datetime.datetime.')

TypeError: Plotting requires coordinates to be numeric or dates of type np.datetime64 or datetime.datetime. If `cftime.datetime` objects are the data requested to be plotted, the following error message results: In [8]: data = xr.DataArray(time, coords=[np.arange(5)], dims=['x'])

In [9]: data.plot()

NotImplementedError Traceback (most recent call last) <ipython-input-9-118f55e0b3d0> in <module>() ----> 1 data.plot()

/Users/spencerclark/xarray-dev/xarray/xarray/plot/plot.pyc in call(self, kwargs) 357 358 def call(self, kwargs): --> 359 return plot(self._da, **kwargs) 360 361 @functools.wraps(hist)

/Users/spencerclark/xarray-dev/xarray/xarray/plot/plot.pyc in plot(darray, row, col, col_wrap, ax, rtol, subplot_kws, **kwargs) 124 125 if contains_cftime_datetimes(darray): --> 126 raise NotImplementedError('Plotting arrays of cftime.datetime objects ' 127 'is currently not possible.') 128

NotImplementedError: Plotting arrays of cftime.datetime objects is currently not possible. ```

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