Skip to content

Commit 11c0523

Browse files
meeseeksmachinejreback
authored andcommitted
Backport PR #22253: Resampling with NaT in TimedeltaIndex raises MemoryError (#22258)
1 parent faa1992 commit 11c0523

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

doc/source/whatsnew/v0.23.5.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Bug Fixes
3030

3131
**Groupby/Resample/Rolling**
3232

33-
-
33+
- Bug in :meth:`DataFrame.resample` when resampling ``NaT`` in ``TimeDeltaIndex`` (:issue:`13223`).
3434
-
3535

3636
**Missing**

pandas/core/resample.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1383,8 +1383,7 @@ def _get_time_delta_bins(self, ax):
13831383
data=[], freq=self.freq, name=ax.name)
13841384
return binner, [], labels
13851385

1386-
start = ax[0]
1387-
end = ax[-1]
1386+
start, end = ax.min(), ax.max()
13881387
labels = binner = TimedeltaIndex(start=start,
13891388
end=end,
13901389
freq=self.freq,

pandas/tests/test_resample.py

+10
Original file line numberDiff line numberDiff line change
@@ -2870,6 +2870,16 @@ def test_asfreq_bug(self):
28702870
freq='1T'))
28712871
assert_frame_equal(result, expected)
28722872

2873+
def test_resample_with_nat(self):
2874+
# GH 13223
2875+
index = pd.to_timedelta(['0s', pd.NaT, '2s'])
2876+
result = DataFrame({'value': [2, 3, 5]}, index).resample('1s').mean()
2877+
expected = DataFrame({'value': [2.5, np.nan, 5.0]},
2878+
index=timedelta_range('0 day',
2879+
periods=3,
2880+
freq='1S'))
2881+
assert_frame_equal(result, expected)
2882+
28732883

28742884
class TestResamplerGrouper(object):
28752885

0 commit comments

Comments
 (0)