Skip to content

Commit fd0b307

Browse files
committed
Fix #12037 Error when Resampling using pd.tseries.offsets.Nano as period
1 parent 0320e3b commit fd0b307

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pandas/tseries/resample.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,11 @@ def _get_time_bins(self, ax):
854854
closed=self.closed,
855855
base=self.base)
856856
tz = ax.tz
857+
# do not call replace() because that will swallow the nanosecond part
858+
# GH #12037
857859
binner = labels = DatetimeIndex(freq=self.freq,
858-
start=first.replace(tzinfo=None),
859-
end=last.replace(tzinfo=None),
860+
start=first,
861+
end=last,
860862
tz=tz,
861863
name=ax.name)
862864

pandas/tseries/tests/test_resample.py

+9
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,15 @@ def test_monthly_resample_error(self):
12241224
# it works!
12251225
ts.resample('M')
12261226

1227+
def test_nanosecond_resample_error(self):
1228+
# GH 12307
1229+
start = 1443707890427
1230+
indx = pd.date_range(start=pd.to_datetime(start),
1231+
periods=10, freq='100n')
1232+
ts = pd.Series(np.random.randn(len(indx)), index=indx)
1233+
r = ts.resample(pd.tseries.offsets.Nano(100))
1234+
r.agg('mean')
1235+
12271236
def test_resample_anchored_intraday(self):
12281237
# #1471, #1458
12291238

0 commit comments

Comments
 (0)