Skip to content

Commit be9f2e7

Browse files
committed
BUG: resampling with NaT in TimedeltaIndex (pandas-dev#13223)
1 parent 43d42ec commit be9f2e7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pandas/tseries/resample.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pandas.core.base import AbstractMethodError, GroupByMixin
88

99
from pandas.core.groupby import (BinGrouper, Grouper, _GroupBy, GroupBy,
10-
SeriesGroupBy, groupby, PanelGroupBy)
10+
SeriesGroupBy, groupby, PanelGroupBy, DataError)
1111

1212
from pandas.tseries.frequencies import to_offset, is_subperiod, is_superperiod
1313
from pandas.tseries.index import DatetimeIndex, date_range
@@ -1202,6 +1202,9 @@ def _get_time_delta_bins(self, ax):
12021202
raise TypeError('axis must be a TimedeltaIndex, but got '
12031203
'an instance of %r' % type(ax).__name__)
12041204

1205+
if len(ax) > 0 and all(ax._isnan):
1206+
raise DataError('axis not valid')
1207+
12051208
if not len(ax):
12061209
binner = labels = TimedeltaIndex(
12071210
data=[], freq=self.freq, name=ax.name)
@@ -1223,7 +1226,7 @@ def _get_time_delta_bins(self, ax):
12231226
binner = binner.insert(0, tslib.NaT)
12241227
labels = labels.insert(0, tslib.NaT)
12251228

1226-
n_NaT = sum([ax_i is tslib.NaT for ax_i in ax])
1229+
n_NaT = ax._isnan.sum()
12271230
bins = np.insert(bins, 0, n_NaT)
12281231

12291232
# Addresses GH #10530

pandas/tseries/tests/test_resample.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,11 @@ def test_resample_timedelta_missing_values(self):
10161016
start='0s', end='2s', freq='1s'))
10171017
assert_series_equal(result, expected)
10181018

1019+
# all NaT
1020+
index = pd.to_timedelta([pd.NaT, pd.NaT, pd.NaT])
1021+
series = pd.Series([2, 3, 5], index=index)
1022+
self.assertRaises(DataError, series.resample('1s').mean)
1023+
10191024
def test_resample_rounding(self):
10201025
# GH 8371
10211026
# odd results when rounding is needed

0 commit comments

Comments
 (0)