@@ -211,6 +211,40 @@ def test_ufunc_coercions(self):
211
211
tm .assert_index_equal (result , exp )
212
212
assert result .freq == 'D'
213
213
214
+ def test_datetimeindex_sub_timestamp_overflow (self ):
215
+ dtimax = pd .to_datetime (['now' , pd .Timestamp .max ])
216
+ dtimin = pd .to_datetime (['now' , pd .Timestamp .min ])
217
+
218
+ tsneg = Timestamp ('1950-01-01' )
219
+ ts_neg_variants = [tsneg ,
220
+ tsneg .to_pydatetime (),
221
+ tsneg .to_datetime64 ().astype ('datetime64[ns]' ),
222
+ tsneg .to_datetime64 ().astype ('datetime64[D]' )]
223
+
224
+ tspos = Timestamp ('1980-01-01' )
225
+ ts_pos_variants = [tspos ,
226
+ tspos .to_pydatetime (),
227
+ tspos .to_datetime64 ().astype ('datetime64[ns]' ),
228
+ tspos .to_datetime64 ().astype ('datetime64[D]' )]
229
+
230
+ for variant in ts_neg_variants :
231
+ with pytest .raises (OverflowError ):
232
+ dtimax - variant
233
+
234
+ expected = pd .Timestamp .max .value - tspos .value
235
+ for variant in ts_pos_variants :
236
+ res = dtimax - variant
237
+ assert res [1 ].value == expected
238
+
239
+ expected = pd .Timestamp .min .value - tsneg .value
240
+ for variant in ts_neg_variants :
241
+ res = dtimin - variant
242
+ assert res [1 ].value == expected
243
+
244
+ for variant in ts_pos_variants :
245
+ with pytest .raises (OverflowError ):
246
+ dtimin - variant
247
+
214
248
def test_week_of_month_frequency (self ):
215
249
# GH 5348: "ValueError: Could not evaluate WOM-1SUN" shouldn't raise
216
250
d1 = date (2002 , 9 , 1 )
0 commit comments