Skip to content

Commit 4799022

Browse files
committed
fixed asfreq in Resampler.asfreq using TDI
1 parent 62d9f8c commit 4799022

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
@@ -707,6 +707,7 @@ Groupby/Resample/Rolling
707707
- Multiple bugs in :func:`pandas.core.Rolling.min` with ``closed='left'` and a
708708
datetime-like index leading to incorrect results and also segfault. (:issue:`21704`)
709709
- Bug in :meth:`Resampler.apply` when passing postiional arguments to applied func (:issue:`14615`).
710+
- Bug in :meth:`Resampler.asfreq` when frequency of ``TimedeltaIndex`` is a subperiod of a new frequency (:issue:`13022`).
710711

711712
Sparse
712713
^^^^^^

pandas/core/resample.py

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

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

11711161

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

@@ -2939,6 +2934,17 @@ def test_resample_with_nat(self):
29392934
freq='1S'))
29402935
assert_frame_equal(result, expected)
29412936

2937+
def test_resample_as_freq_with_subperiod(self):
2938+
# GH 13022
2939+
index = timedelta_range('00:00:00', '00:10:00', freq='5T')
2940+
df = DataFrame(data={'value': [1, 5, 10]}, index=index)
2941+
result = df.resample('2T').asfreq()
2942+
expected_data = {'value': [1, np.nan, np.nan, np.nan, np.nan, 10]}
2943+
expected = DataFrame(data=expected_data,
2944+
index=timedelta_range('00:00:00',
2945+
'00:10:00', freq='2T'))
2946+
tm.assert_frame_equal(result, expected)
2947+
29422948

29432949
class TestResamplerGrouper(object):
29442950

0 commit comments

Comments
 (0)