@@ -199,6 +199,40 @@ def test_ufunc_coercions(self):
199199 tm .assert_index_equal (result , exp )
200200 assert result .freq == 'D'
201201
202+ def test_datetimeindex_sub_timestamp_overflow (self ):
203+ dtimax = pd .to_datetime (['now' , pd .Timestamp .max ])
204+ dtimin = pd .to_datetime (['now' , pd .Timestamp .min ])
205+
206+ tsneg = Timestamp ('1950-01-01' )
207+ ts_neg_variants = [tsneg ,
208+ tsneg .to_pydatetime (),
209+ tsneg .to_datetime64 ().astype ('datetime64[ns]' ),
210+ tsneg .to_datetime64 ().astype ('datetime64[D]' )]
211+
212+ tspos = Timestamp ('1980-01-01' )
213+ ts_pos_variants = [tspos ,
214+ tspos .to_pydatetime (),
215+ tspos .to_datetime64 ().astype ('datetime64[ns]' ),
216+ tspos .to_datetime64 ().astype ('datetime64[D]' )]
217+
218+ for variant in ts_neg_variants :
219+ with pytest .raises (OverflowError ):
220+ dtimax - variant
221+
222+ expected = pd .Timestamp .max .value - tspos .value
223+ for variant in ts_pos_variants :
224+ res = dtimax - variant
225+ assert res [1 ].value == expected
226+
227+ expected = pd .Timestamp .min .value - tsneg .value
228+ for variant in ts_neg_variants :
229+ res = dtimin - variant
230+ assert res [1 ].value == expected
231+
232+ for variant in ts_pos_variants :
233+ with pytest .raises (OverflowError ):
234+ dtimin - variant
235+
202236
203237# GH 10699
204238@pytest .mark .parametrize ('klass,assert_func' , zip ([Series , DatetimeIndex ],
0 commit comments