@@ -1195,6 +1195,18 @@ def test_sub_single_tz(self):
1195
1195
expected = Series ([Timedelta ('-2days' )])
1196
1196
assert_series_equal (result , expected )
1197
1197
1198
+ def test_dt64tz_series_sub_dtitz (self ):
1199
+ # GH#19071 subtracting tzaware DatetimeIndex from tzaware Series
1200
+ # (with same tz) raises, fixed by #19024
1201
+ dti = pd .date_range ('1999-09-30' , periods = 10 , tz = 'US/Pacific' )
1202
+ ser = pd .Series (dti )
1203
+ expected = pd .Series (pd .TimedeltaIndex (['0days' ] * 10 ))
1204
+
1205
+ res = dti - ser
1206
+ tm .assert_series_equal (res , expected )
1207
+ res = ser - dti
1208
+ tm .assert_series_equal (res , expected )
1209
+
1198
1210
def test_sub_datetime_compat (self ):
1199
1211
# see gh-14088
1200
1212
s = Series ([datetime (2016 , 8 , 23 , 12 , tzinfo = pytz .utc ), pd .NaT ])
@@ -1317,6 +1329,37 @@ def test_datetime64_ops_nat(self):
1317
1329
with pytest .raises (TypeError ):
1318
1330
nat_series_dtype_timestamp / 1
1319
1331
1332
+ def test_dt64series_arith_overflow (self ):
1333
+ # GH#12534, fixed by #19024
1334
+ dt = pd .Timestamp ('1700-01-31' )
1335
+ td = pd .Timedelta ('20000 Days' )
1336
+ dti = pd .date_range ('1949-09-30' , freq = '100Y' , periods = 4 )
1337
+ ser = pd .Series (dti )
1338
+ with pytest .raises (OverflowError ):
1339
+ ser - dt
1340
+ with pytest .raises (OverflowError ):
1341
+ dt - ser
1342
+ with pytest .raises (OverflowError ):
1343
+ ser + td
1344
+ with pytest .raises (OverflowError ):
1345
+ td + ser
1346
+
1347
+ ser .iloc [- 1 ] = pd .NaT
1348
+ expected = pd .Series (['2004-10-03' , '2104-10-04' , '2204-10-04' , 'NaT' ],
1349
+ dtype = 'datetime64[ns]' )
1350
+ res = ser + td
1351
+ tm .assert_series_equal (res , expected )
1352
+ res = td + ser
1353
+ tm .assert_series_equal (res , expected )
1354
+
1355
+ ser .iloc [1 :] = pd .NaT
1356
+ expected = pd .Series (['91279 Days' , 'NaT' , 'NaT' , 'NaT' ],
1357
+ dtype = 'timedelta64[ns]' )
1358
+ res = ser - dt
1359
+ tm .assert_series_equal (res , expected )
1360
+ res = dt - ser
1361
+ tm .assert_series_equal (res , - expected )
1362
+
1320
1363
1321
1364
class TestSeriesOperators (TestData ):
1322
1365
def test_op_method (self ):
0 commit comments