Skip to content

Commit 3b466e8

Browse files
committed
Moved code for fix to _get_time_delta_bins function
1 parent 19ba1c8 commit 3b466e8

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

pandas/tseries/resample.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,21 @@ def _get_time_delta_bins(self, ax):
229229
binner = labels = TimedeltaIndex(data=[], freq=self.freq, name=ax.name)
230230
return binner, [], labels
231231

232-
first, last = ax.min(), ax.max()
233-
234-
labels = binner = TimedeltaIndex(start=first,
235-
end=last,
232+
labels = binner = TimedeltaIndex(start=ax[0],
233+
end=ax[-1],
236234
freq=self.freq,
237235
name=ax.name)
238236

239237
end_stamps = labels + 1
238+
239+
# Addresses GH #10530
240+
if self.base > 0:
241+
last = labels[-1]
242+
labels_shifted = labels.copy()
243+
labels_shifted = labels_shifted.shift(self.base)
244+
labels_shifted = labels_shifted[labels_shifted <= last]
245+
labels = labels_shifted
246+
240247
bins = ax.searchsorted(end_stamps, side='left')
241248

242249
return binner, bins, labels
@@ -326,11 +333,6 @@ def _resample_timestamps(self, kind=None):
326333

327334
result.index = result.index + loffset
328335

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]
333-
334336
return result
335337

336338
def _resample_periods(self):

0 commit comments

Comments
 (0)