@@ -357,13 +357,15 @@ def test_subtraction_ops(self):
357
357
expected = DatetimeIndex (["20121231" , NaT , "20121230" ], name = "foo" )
358
358
tm .assert_index_equal (result , expected )
359
359
360
- def test_subtraction_ops_with_tz (self ):
360
+ def test_subtraction_ops_with_tz (self , box_with_array ):
361
361
362
362
# check that dt/dti subtraction ops with tz are validated
363
363
dti = pd .date_range ("20130101" , periods = 3 )
364
+ dti = tm .box_expected (dti , box_with_array )
364
365
ts = Timestamp ("20130101" )
365
366
dt = ts .to_pydatetime ()
366
367
dti_tz = pd .date_range ("20130101" , periods = 3 ).tz_localize ("US/Eastern" )
368
+ dti_tz = tm .box_expected (dti_tz , box_with_array )
367
369
ts_tz = Timestamp ("20130101" ).tz_localize ("US/Eastern" )
368
370
ts_tz2 = Timestamp ("20130101" ).tz_localize ("CET" )
369
371
dt_tz = ts_tz .to_pydatetime ()
@@ -387,59 +389,58 @@ def _check(result, expected):
387
389
_check (result , expected )
388
390
389
391
# tz mismatches
390
- msg = "Timestamp subtraction must have the same timezones or no timezones "
392
+ msg = "Cannot subtract tz-naive and tz-aware datetime-like objects. "
391
393
with pytest .raises (TypeError , match = msg ):
392
394
dt_tz - ts
393
395
msg = "can't subtract offset-naive and offset-aware datetimes"
394
396
with pytest .raises (TypeError , match = msg ):
395
397
dt_tz - dt
396
- msg = "Timestamp subtraction must have the same timezones or no timezones"
397
- with pytest .raises (TypeError , match = msg ):
398
- dt_tz - ts_tz2
399
398
msg = "can't subtract offset-naive and offset-aware datetimes"
400
399
with pytest .raises (TypeError , match = msg ):
401
400
dt - dt_tz
402
- msg = "Timestamp subtraction must have the same timezones or no timezones "
401
+ msg = "Cannot subtract tz-naive and tz-aware datetime-like objects. "
403
402
with pytest .raises (TypeError , match = msg ):
404
403
ts - dt_tz
405
404
with pytest .raises (TypeError , match = msg ):
406
405
ts_tz2 - ts
407
406
with pytest .raises (TypeError , match = msg ):
408
407
ts_tz2 - dt
409
- with pytest .raises (TypeError , match = msg ):
410
- ts_tz - ts_tz2
411
408
409
+ msg = "Cannot subtract tz-naive and tz-aware"
412
410
# with dti
413
411
with pytest .raises (TypeError , match = msg ):
414
412
dti - ts_tz
415
413
with pytest .raises (TypeError , match = msg ):
416
414
dti_tz - ts
417
- with pytest .raises (TypeError , match = msg ):
418
- dti_tz - ts_tz2
419
415
420
416
result = dti_tz - dt_tz
421
417
expected = TimedeltaIndex (["0 days" , "1 days" , "2 days" ])
422
- tm .assert_index_equal (result , expected )
418
+ expected = tm .box_expected (expected , box_with_array )
419
+ tm .assert_equal (result , expected )
423
420
424
421
result = dt_tz - dti_tz
425
422
expected = TimedeltaIndex (["0 days" , "-1 days" , "-2 days" ])
426
- tm .assert_index_equal (result , expected )
423
+ expected = tm .box_expected (expected , box_with_array )
424
+ tm .assert_equal (result , expected )
427
425
428
426
result = dti_tz - ts_tz
429
427
expected = TimedeltaIndex (["0 days" , "1 days" , "2 days" ])
430
- tm .assert_index_equal (result , expected )
428
+ expected = tm .box_expected (expected , box_with_array )
429
+ tm .assert_equal (result , expected )
431
430
432
431
result = ts_tz - dti_tz
433
432
expected = TimedeltaIndex (["0 days" , "-1 days" , "-2 days" ])
434
- tm .assert_index_equal (result , expected )
433
+ expected = tm .box_expected (expected , box_with_array )
434
+ tm .assert_equal (result , expected )
435
435
436
436
result = td - td
437
437
expected = Timedelta ("0 days" )
438
438
_check (result , expected )
439
439
440
440
result = dti_tz - td
441
441
expected = DatetimeIndex (["20121231" , "20130101" , "20130102" ], tz = "US/Eastern" )
442
- tm .assert_index_equal (result , expected )
442
+ expected = tm .box_expected (expected , box_with_array )
443
+ tm .assert_equal (result , expected )
443
444
444
445
def test_dti_tdi_numeric_ops (self ):
445
446
# These are normally union/diff set-like ops
0 commit comments