Skip to content

Commit 1f80bba

Browse files
committed
fixed asfreq in Resampler.asfreq using TDI
1 parent 9122952 commit 1f80bba

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ Groupby/Resample/Rolling
703703
- Multiple bugs in :func:`pandas.core.Rolling.min` with ``closed='left'` and a
704704
datetime-like index leading to incorrect results and also segfault. (:issue:`21704`)
705705
- Bug in :meth:`Resampler.apply` when passing postiional arguments to applied func (:issue:`14615`).
706+
- Bug in :meth:`Resampler.asfreq` when frequency of ``TimedeltaIndex`` is a subperiod of a new frequency (:issue:`13022`).
706707

707708
Sparse
708709
^^^^^^

pandas/core/resample.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ def _adjust_binner_for_upsample(self, binner):
11581158
""" adjust our binner when upsampling """
11591159
ax = self.ax
11601160

1161-
if is_subperiod(ax.freq, self.freq):
1161+
if is_subperiod(ax.freq, self.freq) and ax.freq <= self.freq:
11621162
# We are actually downsampling
11631163
# but are in the asfreq path
11641164
# GH 12926

pandas/tests/test_resample.py

+8
Original file line numberDiff line numberDiff line change
@@ -2939,6 +2939,14 @@ def test_resample_with_nat(self):
29392939
freq='1S'))
29402940
assert_frame_equal(result, expected)
29412941

2942+
def test_resample_as_freq_with_subperiod(self):
2943+
# GH 13022
2944+
index = pd.timedelta_range('00:00:00', '00:10:00', freq='5T')
2945+
df = DataFrame(data=[[1, 3], [-5, 10], [0, 0]], index=index)
2946+
result = df.resample('1T').asfreq()
2947+
expected = df.resample('1T').mean()
2948+
assert len(result) == len(expected)
2949+
29422950

29432951
class TestResamplerGrouper(object):
29442952

0 commit comments

Comments
 (0)