Skip to content

Commit 89b025b

Browse files
committed
BUG: resampling with NaT in TimedeltaIndex (#13223)
1 parent ef2cf61 commit 89b025b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pandas/tseries/resample.py

+5-2
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
@@ -1219,6 +1219,9 @@ def _get_time_delta_bins(self, ax):
12191219
raise TypeError('axis must be a TimedeltaIndex, but got '
12201220
'an instance of %r' % type(ax).__name__)
12211221

1222+
if len(ax) > 0 and all(ax._isnan):
1223+
raise DataError('axis not valid')
1224+
12221225
if not len(ax):
12231226
binner = labels = TimedeltaIndex(
12241227
data=[], freq=self.freq, name=ax.name)
@@ -1240,7 +1243,7 @@ def _get_time_delta_bins(self, ax):
12401243
binner = binner.insert(0, tslib.NaT)
12411244
labels = labels.insert(0, tslib.NaT)
12421245

1243-
n_NaT = sum([ax_i is tslib.NaT for ax_i in ax])
1246+
n_NaT = ax._isnan.sum()
12441247
bins = np.insert(bins, 0, n_NaT)
12451248

12461249
# Addresses GH #10530

pandas/tseries/tests/test_resample.py

+5
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,11 @@ def test_resample_timedelta_missing_values(self):
10341034
start='0s', end='2s', freq='1s'))
10351035
assert_series_equal(result, expected)
10361036

1037+
# all NaT
1038+
index = pd.to_timedelta([pd.NaT, pd.NaT, pd.NaT])
1039+
series = pd.Series([2, 3, 5], index=index)
1040+
self.assertRaises(DataError, series.resample('1s').mean)
1041+
10371042
def test_resample_rounding(self):
10381043
# GH 8371
10391044
# odd results when rounding is needed

0 commit comments

Comments
 (0)