home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 245649333

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
245649333 MDU6SXNzdWUyNDU2NDkzMzM= 1490 Resample not working when time coordinate is timezone aware 28712155 open 0     4 2017-07-26T08:47:55Z 2021-07-13T15:30:24Z   NONE      

hi all, here is the code to reproduce the bug

import pandas as pd import xarray as xr time1 = pd.date_range('2000-01-01', freq='H', periods=365 * 24) #timezone naïve time2 = pd.date_range('2000-01-01', freq='H', periods=365 * 24, tz='UTC') #timezone aware ds1 = xr.Dataset({'foo': ('time', np.arange(365 * 24)), 'time': time1}) ds2 = xr.Dataset({'foo': ('time', np.arange(365 * 24)), 'time': time2}) ds1.resample('3H', 'time', how='mean') #works fine ds2.resample('3H', 'time', how='mean') #returns an error

This last line returns the following error:

```

TypeError Traceback (most recent call last) <ipython-input-17-0de4b0d703bd> in <module>() 4 ds2 = xr.Dataset({'foo': ('time', np.arange(365 * 24)), 'time': time2}) 5 ds1.resample('3H', 'time', how='mean') ----> 6 ds.resample('3H', 'time', how='mean')

~/.virtualenvs/planck3/lib/python3.5/site-packages/xarray/core/common.py in resample(self, freq, dim, how, skipna, closed, label, base, keep_attrs) 546 time_grouper = pd.TimeGrouper(freq=freq, how=how, closed=closed, 547 label=label, base=base) --> 548 gb = self._groupby_cls(self, group, grouper=time_grouper) 549 if isinstance(how, basestring): 550 f = getattr(gb, how)

~/.virtualenvs/planck3/lib/python3.5/site-packages/xarray/core/groupby.py in init(self, obj, group, squeeze, grouper, bins, cut_kwargs) 243 raise ValueError('index must be monotonic for resampling') 244 s = pd.Series(np.arange(index.size), index) --> 245 first_items = s.groupby(grouper).first() 246 if first_items.isnull().any(): 247 full_index = first_items.index

~/.virtualenvs/planck3/lib/python3.5/site-packages/pandas/core/generic.py in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, kwargs) 4414 return groupby(self, by=by, axis=axis, level=level, as_index=as_index, 4415 sort=sort, group_keys=group_keys, squeeze=squeeze, -> 4416 kwargs) 4417 4418 def asfreq(self, freq, method=None, how=None, normalize=False,

~/.virtualenvs/planck3/lib/python3.5/site-packages/pandas/core/groupby.py in groupby(obj, by, kwds) 1697 raise TypeError('invalid type: %s' % type(obj)) 1698 -> 1699 return klass(obj, by, kwds) 1700 1701

~/.virtualenvs/planck3/lib/python3.5/site-packages/pandas/core/groupby.py in init(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, **kwargs) 390 level=level, 391 sort=sort, --> 392 mutated=self.mutated) 393 394 self.obj = obj

~/.virtualenvs/planck3/lib/python3.5/site-packages/pandas/core/groupby.py in _get_grouper(obj, key, axis, level, sort, mutated) 2605 # a passed-in Grouper, directly convert 2606 if isinstance(key, Grouper): -> 2607 binner, grouper, obj = key._get_grouper(obj) 2608 if key.key is None: 2609 return grouper, [], obj

~/.virtualenvs/planck3/lib/python3.5/site-packages/pandas/core/resample.py in _get_grouper(self, obj) 1093 def _get_grouper(self, obj): 1094 # create the resampler and return our binner -> 1095 r = self._get_resampler(obj) 1096 r._set_binner() 1097 return r.binner, r.grouper, r.obj

~/.virtualenvs/planck3/lib/python3.5/site-packages/pandas/core/resample.py in _get_resampler(self, obj, kind) 1089 raise TypeError("Only valid with DatetimeIndex, " 1090 "TimedeltaIndex or PeriodIndex, " -> 1091 "but got an instance of %r" % type(ax).name) 1092 1093 def _get_grouper(self, obj):

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

My config: xarray==0.9.6 pandas==0.20.3 numpy==1.13.1 python-dateutil==2.6.1 six==1.10.0 pytz==2017.2

Tested on python 2.7 and python 3.5.2

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1490/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 4 rows from issue in issue_comments
Powered by Datasette · Queries took 0.911ms · About: xarray-datasette