Skip to content

Commit f118371

Browse files
committed
Fixed loffset with numpy timedelta
1 parent 982f309 commit f118371

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

pandas/core/resample.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,9 @@ def _apply_loffset(self, result):
365365
the result of resample
366366
"""
367367

368+
loffset_types = (DateOffset, timedelta, np.timedelta64)
368369
needs_offset = (
369-
isinstance(self.loffset, (DateOffset, timedelta)) and
370+
isinstance(self.loffset, loffset_types) and
370371
isinstance(result.index, DatetimeIndex) and
371372
len(result.index) > 0
372373
)

pandas/tests/test_resample.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -1173,27 +1173,19 @@ def test_resample_frame_basic(self):
11731173
df.resample('M', kind='period').mean()
11741174
df.resample('W-WED', kind='period').mean()
11751175

1176-
def test_resample_loffset(self):
1176+
@pytest.mark.parametrize('loffset', [timedelta(minutes=1),
1177+
'1min', Minute(1),
1178+
np.timedelta64(1, 'm')])
1179+
def test_resample_loffset(self, loffset):
11771180
rng = date_range('1/1/2000 00:00:00', '1/1/2000 00:13:00', freq='min')
11781181
s = Series(np.random.randn(14), index=rng)
11791182

11801183
result = s.resample('5min', closed='right', label='right',
1181-
loffset=timedelta(minutes=1)).mean()
1184+
loffset=loffset).mean()
11821185
idx = date_range('1/1/2000', periods=4, freq='5min')
11831186
expected = Series([s[0], s[1:6].mean(), s[6:11].mean(), s[11:].mean()],
11841187
index=idx + timedelta(minutes=1))
11851188
assert_series_equal(result, expected)
1186-
1187-
expected = s.resample(
1188-
'5min', closed='right', label='right',
1189-
loffset='1min').mean()
1190-
assert_series_equal(result, expected)
1191-
1192-
expected = s.resample(
1193-
'5min', closed='right', label='right',
1194-
loffset=Minute(1)).mean()
1195-
assert_series_equal(result, expected)
1196-
11971189
assert result.index.freq == Minute(5)
11981190

11991191
# from daily

0 commit comments

Comments
 (0)