Skip to content

Commit a3e5f80

Browse files
committed
Fixed MemoryError in resampling with NaT in TimedeltaIndex
1 parent 8206c36 commit a3e5f80

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

doc/source/whatsnew/v0.24.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ Groupby/Resample/Rolling
648648
``SeriesGroupBy`` when the grouping variable only contains NaNs and numpy version < 1.13 (:issue:`21956`).
649649
- Multiple bugs in :func:`pandas.core.Rolling.min` with ``closed='left'` and a
650650
datetime-like index leading to incorrect results and also segfault. (:issue:`21704`)
651-
-
651+
- Bug in :meth:`DataFrame.resample` when resampling NaT in `TimeDeltaIndex` (:issue:`13223`).
652652

653653
Sparse
654654
^^^^^^

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
@@ -2887,6 +2887,16 @@ def test_asfreq_bug(self):
28872887
freq='1T'))
28882888
assert_frame_equal(result, expected)
28892889

2890+
def test_resampling_with_nat(self):
2891+
# GH 13223
2892+
index = pd.to_timedelta(['0s', pd.NaT, '2s'])
2893+
result = DataFrame({'value': [2, 3, 5]}, index).resample('1s').mean()
2894+
expected = DataFrame({'value': [2.5, np.nan, 5.0]},
2895+
index=timedelta_range('0 day',
2896+
periods=3,
2897+
freq='1S'))
2898+
assert_frame_equal(result, expected)
2899+
28902900

28912901
class TestResamplerGrouper(object):
28922902

0 commit comments

Comments
 (0)