@@ -360,7 +360,7 @@ def test_resolution(self):
360
360
tz = tz )
361
361
self .assertEqual (idx .resolution , expected )
362
362
363
- def test_add_iadd (self ):
363
+ def test_union (self ):
364
364
for tz in self .tz :
365
365
# union
366
366
rng1 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
@@ -378,17 +378,34 @@ def test_add_iadd(self):
378
378
for rng , other , expected in [(rng1 , other1 , expected1 ),
379
379
(rng2 , other2 , expected2 ),
380
380
(rng3 , other3 , expected3 )]:
381
- # GH9094
382
- with tm .assert_produces_warning (FutureWarning ):
383
- result_add = rng + other
384
- result_union = rng .union (other )
385
381
386
- tm . assert_index_equal ( result_add , expected )
382
+ result_union = rng . union ( other )
387
383
tm .assert_index_equal (result_union , expected )
388
- # GH9094
389
- with tm .assert_produces_warning (FutureWarning ):
384
+
385
+ def test_add_iadd (self ):
386
+ for tz in self .tz :
387
+ rng1 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
388
+ other1 = pd .date_range ('1/6/2000' , freq = 'D' , periods = 5 , tz = tz )
389
+ expected1 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 10 , tz = tz )
390
+
391
+ rng2 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
392
+ other2 = pd .date_range ('1/4/2000' , freq = 'D' , periods = 5 , tz = tz )
393
+ expected2 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 8 , tz = tz )
394
+
395
+ rng3 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
396
+ other3 = pd .DatetimeIndex ([], tz = tz )
397
+ expected3 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
398
+
399
+ for rng , other , expected in [(rng1 , other1 , expected1 ),
400
+ (rng2 , other2 , expected2 ),
401
+ (rng3 , other3 , expected3 )]:
402
+ # previously performed setop (deprecated in 0.16.0), now
403
+ # raises TypeError (GH..)
404
+ with tm .assertRaises (TypeError ):
405
+ rng + other
406
+
407
+ with tm .assertRaises (TypeError ):
390
408
rng += other
391
- tm .assert_index_equal (rng , expected )
392
409
393
410
# offset
394
411
offsets = [pd .offsets .Hour (2 ), timedelta (hours = 2 ),
@@ -421,7 +438,26 @@ def test_add_iadd(self):
421
438
with tm .assertRaisesRegexp (TypeError , msg ):
422
439
Timestamp ('2011-01-01' ) + idx
423
440
424
- def test_sub_isub (self ):
441
+ def test_add_dti_dti (self ):
442
+ # previously performed setop (deprecated in 0.16.0), now raises
443
+ # TypeError (GH..)
444
+
445
+ dti = date_range ('20130101' , periods = 3 )
446
+ dti_tz = date_range ('20130101' , periods = 3 ).tz_localize ('US/Eastern' )
447
+
448
+ with tm .assertRaises (TypeError ):
449
+ dti + dti
450
+
451
+ with tm .assertRaises (TypeError ):
452
+ dti_tz + dti_tz
453
+
454
+ with tm .assertRaises (TypeError ):
455
+ dti_tz + dti
456
+
457
+ with tm .assertRaises (TypeError ):
458
+ dti + dti_tz
459
+
460
+ def test_diff (self ):
425
461
for tz in self .tz :
426
462
# diff
427
463
rng1 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
@@ -439,9 +475,22 @@ def test_sub_isub(self):
439
475
for rng , other , expected in [(rng1 , other1 , expected1 ),
440
476
(rng2 , other2 , expected2 ),
441
477
(rng3 , other3 , expected3 )]:
442
- result_union = rng .difference (other )
478
+ result_diff = rng .difference (other )
479
+ tm .assert_index_equal (result_diff , expected )
443
480
444
- tm .assert_index_equal (result_union , expected )
481
+ def test_sub_isub (self ):
482
+ for tz in self .tz :
483
+ rng1 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
484
+ other1 = pd .date_range ('1/6/2000' , freq = 'D' , periods = 5 , tz = tz )
485
+ expected1 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
486
+
487
+ rng2 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
488
+ other2 = pd .date_range ('1/4/2000' , freq = 'D' , periods = 5 , tz = tz )
489
+ expected2 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 3 , tz = tz )
490
+
491
+ rng3 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
492
+ other3 = pd .DatetimeIndex ([], tz = tz )
493
+ expected3 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
445
494
446
495
# offset
447
496
offsets = [pd .offsets .Hour (2 ), timedelta (hours = 2 ),
@@ -466,6 +515,30 @@ def test_sub_isub(self):
466
515
rng -= 1
467
516
tm .assert_index_equal (rng , expected )
468
517
518
+ def test_sub_dti_dti (self ):
519
+ # previously performed setop (deprecated in 0.16.0), now changed to
520
+ # return subtraction -> TimeDeltaIndex (GH ...)
521
+
522
+ dti = date_range ('20130101' , periods = 3 )
523
+ dti_tz = date_range ('20130101' , periods = 3 ).tz_localize ('US/Eastern' )
524
+ dti_tz2 = date_range ('20130101' , periods = 3 ).tz_localize ('UTC' )
525
+ expected = TimedeltaIndex ([0 , 0 , 0 ])
526
+
527
+ result = dti - dti
528
+ tm .assert_index_equal (result , expected )
529
+
530
+ result = dti_tz - dti_tz
531
+ tm .assert_index_equal (result , expected )
532
+
533
+ with tm .assertRaises (TypeError ):
534
+ dti_tz - dti
535
+
536
+ with tm .assertRaises (TypeError ):
537
+ dti - dti_tz
538
+
539
+ with tm .assertRaises (TypeError ):
540
+ dti_tz - dti_tz2
541
+
469
542
def test_sub_period (self ):
470
543
# GH 13078
471
544
# not supported, check TypeError
@@ -1239,50 +1312,6 @@ def _check(result, expected):
1239
1312
['20121231' , '20130101' , '20130102' ], tz = 'US/Eastern' )
1240
1313
tm .assert_index_equal (result , expected )
1241
1314
1242
- def test_dti_dti_deprecated_ops (self ):
1243
-
1244
- # deprecated in 0.16.0 (GH9094)
1245
- # change to return subtraction -> TimeDeltaIndex in 0.17.0
1246
- # shoudl move to the appropriate sections above
1247
-
1248
- dti = date_range ('20130101' , periods = 3 )
1249
- dti_tz = date_range ('20130101' , periods = 3 ).tz_localize ('US/Eastern' )
1250
-
1251
- with tm .assert_produces_warning (FutureWarning ):
1252
- result = dti - dti
1253
- expected = Index ([])
1254
- tm .assert_index_equal (result , expected )
1255
-
1256
- with tm .assert_produces_warning (FutureWarning ):
1257
- result = dti + dti
1258
- expected = dti
1259
- tm .assert_index_equal (result , expected )
1260
-
1261
- with tm .assert_produces_warning (FutureWarning ):
1262
- result = dti_tz - dti_tz
1263
- expected = Index ([])
1264
- tm .assert_index_equal (result , expected )
1265
-
1266
- with tm .assert_produces_warning (FutureWarning ):
1267
- result = dti_tz + dti_tz
1268
- expected = dti_tz
1269
- tm .assert_index_equal (result , expected )
1270
-
1271
- with tm .assert_produces_warning (FutureWarning ):
1272
- result = dti_tz - dti
1273
- expected = dti_tz
1274
- tm .assert_index_equal (result , expected )
1275
-
1276
- with tm .assert_produces_warning (FutureWarning ):
1277
- result = dti - dti_tz
1278
- expected = dti
1279
- tm .assert_index_equal (result , expected )
1280
-
1281
- with tm .assert_produces_warning (FutureWarning ):
1282
- self .assertRaises (TypeError , lambda : dti_tz + dti )
1283
- with tm .assert_produces_warning (FutureWarning ):
1284
- self .assertRaises (TypeError , lambda : dti + dti_tz )
1285
-
1286
1315
def test_dti_tdi_numeric_ops (self ):
1287
1316
1288
1317
# These are normally union/diff set-like ops
@@ -2053,19 +2082,17 @@ def test_add_iadd(self):
2053
2082
(rng7 , other7 , expected7 )]:
2054
2083
2055
2084
# GH9094
2056
- with tm .assert_produces_warning ( FutureWarning ):
2057
- result_add = rng + other
2085
+ with tm .assertRaises ( TypeError ):
2086
+ rng + other
2058
2087
2059
2088
result_union = rng .union (other )
2060
2089
2061
- tm .assert_index_equal (result_add , expected )
2062
2090
tm .assert_index_equal (result_union , expected )
2063
2091
2064
2092
# GH 6527
2065
2093
# GH9094
2066
- with tm .assert_produces_warning ( FutureWarning ):
2094
+ with tm .assertRaises ( TypeError ):
2067
2095
rng += other
2068
- tm .assert_index_equal (rng , expected )
2069
2096
2070
2097
# offset
2071
2098
# DateOffset
0 commit comments