Skip to content

Commit 7d16b62

Browse files
committed
fixed asfreq in Resampler.asfreq using TDI
1 parent 9e362a6 commit 7d16b62

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ Groupby/Resample/Rolling
709709
datetime-like index leading to incorrect results and also segfault. (:issue:`21704`)
710710
- Bug in :meth:`Resampler.apply` when passing postiional arguments to applied func (:issue:`14615`).
711711
- Bug in :meth:`Series.resample` when passing ``numpy.timedelta64`` to `loffset` kwarg (:issue:`7687`).
712+
- Bug in :meth:`Resampler.asfreq` when frequency of ``TimedeltaIndex`` is a subperiod of a new frequency (:issue:`13022`).
712713

713714
Sparse
714715
^^^^^^

pandas/core/resample.py

-10
Original file line numberDiff line numberDiff line change
@@ -1157,16 +1157,6 @@ def _get_binner_for_time(self):
11571157

11581158
def _adjust_binner_for_upsample(self, binner):
11591159
""" adjust our binner when upsampling """
1160-
ax = self.ax
1161-
1162-
if is_subperiod(ax.freq, self.freq):
1163-
# We are actually downsampling
1164-
# but are in the asfreq path
1165-
# GH 12926
1166-
if self.closed == 'right':
1167-
binner = binner[1:]
1168-
else:
1169-
binner = binner[:-1]
11701160
return binner
11711161

11721162

pandas/tests/test_resample.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,7 @@ def test_asfreq(self, series_and_frame, freq):
626626
obj = series_and_frame
627627

628628
result = obj.resample(freq).asfreq()
629-
if freq == '2D':
630-
new_index = obj.index.take(np.arange(0, len(obj.index), 2))
631-
new_index.freq = to_offset('2D')
632-
else:
633-
new_index = self.create_index(obj.index[0], obj.index[-1],
634-
freq=freq)
629+
new_index = self.create_index(obj.index[0], obj.index[-1], freq=freq)
635630
expected = obj.reindex(new_index)
636631
assert_almost_equal(result, expected)
637632

@@ -2932,6 +2927,17 @@ def test_resample_with_nat(self):
29322927
freq='1S'))
29332928
assert_frame_equal(result, expected)
29342929

2930+
def test_resample_as_freq_with_subperiod(self):
2931+
# GH 13022
2932+
index = timedelta_range('00:00:00', '00:10:00', freq='5T')
2933+
df = DataFrame(data={'value': [1, 5, 10]}, index=index)
2934+
result = df.resample('2T').asfreq()
2935+
expected_data = {'value': [1, np.nan, np.nan, np.nan, np.nan, 10]}
2936+
expected = DataFrame(data=expected_data,
2937+
index=timedelta_range('00:00:00',
2938+
'00:10:00', freq='2T'))
2939+
tm.assert_frame_equal(result, expected)
2940+
29352941

29362942
class TestResamplerGrouper(object):
29372943

0 commit comments

Comments
 (0)