@@ -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,12 @@ 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 ):
390
- rng += other
391
- tm .assert_index_equal (rng , expected )
384
+
385
+ def test_add_iadd (self ):
386
+ for tz in self .tz :
392
387
393
388
# offset
394
389
offsets = [pd .offsets .Hour (2 ), timedelta (hours = 2 ),
@@ -421,7 +416,26 @@ def test_add_iadd(self):
421
416
with tm .assertRaisesRegexp (TypeError , msg ):
422
417
Timestamp ('2011-01-01' ) + idx
423
418
424
- def test_sub_isub (self ):
419
+ def test_add_dti_dti (self ):
420
+ # previously performed setop (deprecated in 0.16.0), now raises
421
+ # TypeError (GH14164)
422
+
423
+ dti = date_range ('20130101' , periods = 3 )
424
+ dti_tz = date_range ('20130101' , periods = 3 ).tz_localize ('US/Eastern' )
425
+
426
+ with tm .assertRaises (TypeError ):
427
+ dti + dti
428
+
429
+ with tm .assertRaises (TypeError ):
430
+ dti_tz + dti_tz
431
+
432
+ with tm .assertRaises (TypeError ):
433
+ dti_tz + dti
434
+
435
+ with tm .assertRaises (TypeError ):
436
+ dti + dti_tz
437
+
438
+ def test_difference (self ):
425
439
for tz in self .tz :
426
440
# diff
427
441
rng1 = pd .date_range ('1/1/2000' , freq = 'D' , periods = 5 , tz = tz )
@@ -439,19 +453,22 @@ def test_sub_isub(self):
439
453
for rng , other , expected in [(rng1 , other1 , expected1 ),
440
454
(rng2 , other2 , expected2 ),
441
455
(rng3 , other3 , expected3 )]:
442
- result_union = rng .difference (other )
456
+ result_diff = rng .difference (other )
457
+ tm .assert_index_equal (result_diff , expected )
443
458
444
- tm .assert_index_equal (result_union , expected )
459
+ def test_sub_isub (self ):
460
+ for tz in self .tz :
445
461
446
462
# offset
447
463
offsets = [pd .offsets .Hour (2 ), timedelta (hours = 2 ),
448
464
np .timedelta64 (2 , 'h' ), Timedelta (hours = 2 )]
449
465
450
466
for delta in offsets :
451
467
rng = pd .date_range ('2000-01-01' , '2000-02-01' , tz = tz )
452
- result = rng - delta
453
468
expected = pd .date_range ('1999-12-31 22:00' ,
454
469
'2000-01-31 22:00' , tz = tz )
470
+
471
+ result = rng - delta
455
472
tm .assert_index_equal (result , expected )
456
473
rng -= delta
457
474
tm .assert_index_equal (rng , expected )
@@ -466,6 +483,47 @@ def test_sub_isub(self):
466
483
rng -= 1
467
484
tm .assert_index_equal (rng , expected )
468
485
486
+ def test_sub_dti_dti (self ):
487
+ # previously performed setop (deprecated in 0.16.0), now changed to
488
+ # return subtraction -> TimeDeltaIndex (GH ...)
489
+
490
+ dti = date_range ('20130101' , periods = 3 )
491
+ dti_tz = date_range ('20130101' , periods = 3 ).tz_localize ('US/Eastern' )
492
+ dti_tz2 = date_range ('20130101' , periods = 3 ).tz_localize ('UTC' )
493
+ expected = TimedeltaIndex ([0 , 0 , 0 ])
494
+
495
+ result = dti - dti
496
+ tm .assert_index_equal (result , expected )
497
+
498
+ result = dti_tz - dti_tz
499
+ tm .assert_index_equal (result , expected )
500
+
501
+ with tm .assertRaises (TypeError ):
502
+ dti_tz - dti
503
+
504
+ with tm .assertRaises (TypeError ):
505
+ dti - dti_tz
506
+
507
+ with tm .assertRaises (TypeError ):
508
+ dti_tz - dti_tz2
509
+
510
+ # isub
511
+ dti -= dti
512
+ tm .assert_index_equal (dti , expected )
513
+
514
+ # different length raises ValueError
515
+ dti1 = date_range ('20130101' , periods = 3 )
516
+ dti2 = date_range ('20130101' , periods = 4 )
517
+ with tm .assertRaises (ValueError ):
518
+ dti1 - dti2
519
+
520
+ # NaN propagation
521
+ dti1 = DatetimeIndex (['2012-01-01' , np .nan , '2012-01-03' ])
522
+ dti2 = DatetimeIndex (['2012-01-02' , '2012-01-03' , np .nan ])
523
+ expected = TimedeltaIndex (['1 days' , np .nan , np .nan ])
524
+ result = dti2 - dti1
525
+ tm .assert_index_equal (result , expected )
526
+
469
527
def test_sub_period (self ):
470
528
# GH 13078
471
529
# not supported, check TypeError
@@ -1239,50 +1297,6 @@ def _check(result, expected):
1239
1297
['20121231' , '20130101' , '20130102' ], tz = 'US/Eastern' )
1240
1298
tm .assert_index_equal (result , expected )
1241
1299
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
1300
def test_dti_tdi_numeric_ops (self ):
1287
1301
1288
1302
# These are normally union/diff set-like ops
@@ -2005,7 +2019,7 @@ def test_resolution(self):
2005
2019
idx = pd .period_range (start = '2013-04-01' , periods = 30 , freq = freq )
2006
2020
self .assertEqual (idx .resolution , expected )
2007
2021
2008
- def test_add_iadd (self ):
2022
+ def test_union (self ):
2009
2023
# union
2010
2024
rng1 = pd .period_range ('1/1/2000' , freq = 'D' , periods = 5 )
2011
2025
other1 = pd .period_range ('1/6/2000' , freq = 'D' , periods = 5 )
@@ -2031,7 +2045,8 @@ def test_add_iadd(self):
2031
2045
rng5 = pd .PeriodIndex (['2000-01-01 09:01' , '2000-01-01 09:03' ,
2032
2046
'2000-01-01 09:05' ], freq = 'T' )
2033
2047
other5 = pd .PeriodIndex (['2000-01-01 09:01' , '2000-01-01 09:05'
2034
- '2000-01-01 09:08' ], freq = 'T' )
2048
+ '2000-01-01 09:08' ],
2049
+ freq = 'T' )
2035
2050
expected5 = pd .PeriodIndex (['2000-01-01 09:01' , '2000-01-01 09:03' ,
2036
2051
'2000-01-01 09:05' , '2000-01-01 09:08' ],
2037
2052
freq = 'T' )
@@ -2052,20 +2067,19 @@ def test_add_iadd(self):
2052
2067
expected6 ),
2053
2068
(rng7 , other7 , expected7 )]:
2054
2069
2055
- # GH9094
2056
- with tm .assert_produces_warning (FutureWarning ):
2057
- result_add = rng + other
2058
-
2059
2070
result_union = rng .union (other )
2060
-
2061
- tm .assert_index_equal (result_add , expected )
2062
2071
tm .assert_index_equal (result_union , expected )
2063
2072
2064
- # GH 6527
2065
- # GH9094
2066
- with tm .assert_produces_warning (FutureWarning ):
2067
- rng += other
2068
- tm .assert_index_equal (rng , expected )
2073
+ def test_add_iadd (self ):
2074
+ rng = pd .period_range ('1/1/2000' , freq = 'D' , periods = 5 )
2075
+ other = pd .period_range ('1/6/2000' , freq = 'D' , periods = 5 )
2076
+
2077
+ # previously performed setop union, now raises TypeError (GH14164)
2078
+ with tm .assertRaises (TypeError ):
2079
+ rng + other
2080
+
2081
+ with tm .assertRaises (TypeError ):
2082
+ rng += other
2069
2083
2070
2084
# offset
2071
2085
# DateOffset
@@ -2152,7 +2166,7 @@ def test_add_iadd(self):
2152
2166
rng += 1
2153
2167
tm .assert_index_equal (rng , expected )
2154
2168
2155
- def test_sub_isub (self ):
2169
+ def test_difference (self ):
2156
2170
# diff
2157
2171
rng1 = pd .period_range ('1/1/2000' , freq = 'D' , periods = 5 )
2158
2172
other1 = pd .period_range ('1/6/2000' , freq = 'D' , periods = 5 )
@@ -2194,6 +2208,19 @@ def test_sub_isub(self):
2194
2208
result_union = rng .difference (other )
2195
2209
tm .assert_index_equal (result_union , expected )
2196
2210
2211
+ def test_sub_isub (self ):
2212
+
2213
+ # previously performed setop, now raises TypeError (GH14164)
2214
+ # TODO needs to wait on #13077 for decision on result type
2215
+ rng = pd .period_range ('1/1/2000' , freq = 'D' , periods = 5 )
2216
+ other = pd .period_range ('1/6/2000' , freq = 'D' , periods = 5 )
2217
+
2218
+ with tm .assertRaises (TypeError ):
2219
+ rng - other
2220
+
2221
+ with tm .assertRaises (TypeError ):
2222
+ rng -= other
2223
+
2197
2224
# offset
2198
2225
# DateOffset
2199
2226
rng = pd .period_range ('2014' , '2024' , freq = 'A' )
0 commit comments