Skip to content

Resampling with NaT in TimedeltaIndex raises MemoryError #22253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.23.5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Bug Fixes

**Groupby/Resample/Rolling**

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

**Missing**
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,8 +1383,7 @@ def _get_time_delta_bins(self, ax):
data=[], freq=self.freq, name=ax.name)
return binner, [], labels

start = ax[0]
end = ax[-1]
start, end = ax.min(), ax.max()
labels = binner = TimedeltaIndex(start=start,
end=end,
freq=self.freq,
Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -2887,6 +2887,16 @@ def test_asfreq_bug(self):
freq='1T'))
assert_frame_equal(result, expected)

def test_resample_with_nat(self):
# GH 13223
index = pd.to_timedelta(['0s', pd.NaT, '2s'])
result = DataFrame({'value': [2, 3, 5]}, index).resample('1s').mean()
expected = DataFrame({'value': [2.5, np.nan, 5.0]},
index=timedelta_range('0 day',
periods=3,
freq='1S'))
assert_frame_equal(result, expected)


class TestResamplerGrouper(object):

Expand Down