@@ -137,6 +137,10 @@ def resample_op(block, op, axis, count):
137137 v = v [:: self .count ]
138138 result .coords [k ] = v
139139
140+ # Set after we create 'result' - if the original name is None it will
141+ # be replaced by the dask name, so results won't be identical to xarray
142+ result .name = self .da .name
143+
140144 return result
141145
142146 def mean (self ) -> xarray .DataArray :
@@ -170,21 +174,47 @@ def blocked_resample(da: xarray.DataArray, indexer=None, **kwargs) -> BlockedRes
170174 >>> time = pandas.date_range('20010101','20010110', freq='H', closed='left')
171175 >>> hourly = xarray.DataArray(numpy.random.random(time.size), coords=[('time', time)])
172176
177+ >>> blocked_daily_max = blocked_resample(hourly, time='1D').max()
178+ >>> xarray_daily_max = hourly.resample(time='1D').max()
179+ >>> xarray.testing.assert_identical(blocked_daily_max, xarray_daily_max)
180+
173181 >>> blocked_daily_max = blocked_resample(hourly, time=24).max()
174182 >>> xarray_daily_max = hourly.resample(time='1D').max()
175- >>> xarray.testing.assert_equal (blocked_daily_max, xarray_daily_max)
183+ >>> xarray.testing.assert_identical (blocked_daily_max, xarray_daily_max)
176184
177185 Args:
178186 da (:class:`xarray.DataArray`): Resample target
179- indexer/kwargs (Dict[dim, count]): Mapping of dimension name to count along that axis
187+ indexer/kwargs (Dict[dim, count]): Mapping of dimension name to count
188+ along that axis. May be an integer or a time interval understood by
189+ pandas (that interval must evenly divide the dataset).
180190
181191 Returns:
182192 :class:`BlockedResampler`
183193 """
184194 if indexer is None :
185195 indexer = kwargs
186- assert len (indexer ) == 1
196+ else :
197+ indexer = {** indexer , ** kwargs }
198+
199+ if len (indexer ) != 1 :
200+ raise Exception (
201+ f"Only one dimension can be resampled at a time, received { indexer } "
202+ )
203+
187204 dim , count = list (indexer .items ())[0 ]
205+
206+ if not isinstance (count , int ):
207+ # Something like a pandas period, resample the time axis to get the count
208+ counts = da [dim ].resample ({dim : count }).count ()
209+ if counts .min () != counts .max ():
210+ raise Exception (
211+ f"Period '{ count } ' does not evenly divide dimension '{ dim } '"
212+ )
213+ count = counts .values [0 ]
214+
215+ if da .sizes [dim ] % count != 0 :
216+ raise Exception (f"Period '{ count } ' does not evenly divide dimension '{ dim } '" )
217+
188218 return BlockedResampler (da , dim = dim , count = count )
189219
190220
0 commit comments