Skip to content

Commit e4de1fc

Browse files
committed
ENH: Updated code for fixing pandas-dev#10530
1 parent 6f68feb commit e4de1fc

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pandas/tseries/resample.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,11 @@ def _get_time_delta_bins(self, ax):
228228
if not len(ax):
229229
binner = labels = TimedeltaIndex(data=[], freq=self.freq, name=ax.name)
230230
return binner, [], labels
231+
232+
first, last = ax.min(), ax.max()
231233

232-
labels = binner = TimedeltaIndex(start=ax[0],
233-
end=ax[-1],
234+
labels = binner = TimedeltaIndex(start=first,
235+
end=last,
234236
freq=self.freq,
235237
name=ax.name)
236238

@@ -273,6 +275,7 @@ def _resample_timestamps(self, kind=None):
273275
binner = self.binner
274276
obj = self.obj
275277

278+
276279
# Determine if we're downsampling
277280
if axlabels.freq is not None or axlabels.inferred_freq is not None:
278281

@@ -323,14 +326,11 @@ def _resample_timestamps(self, kind=None):
323326

324327
result.index = result.index + loffset
325328

326-
if type(self.base) != int:
327-
raise Exception("Expect base to be int, got {type}"
328-
.format(type = type(self.base)))
329+
if kind == "timedelta" and len(result.index) > 0:
330+
last = result.index[-1]
331+
result.index = result.index.shift(self.base)
332+
result = result.loc[result.index <= last]
329333

330-
if self.base > 0 and self.base < self.freq.n:
331-
shift_freq = type(self.freq)(1)
332-
result.index = result.index.shift(self.base, shift_freq)
333-
334334
return result
335335

336336
def _resample_periods(self):

0 commit comments

Comments
 (0)