11# Arithmetic tests for DataFrame/Series/Index/Array classes that should
22# behave identically.
3- from datetime import datetime , timedelta
3+ from datetime import datetime , timedelta , timezone
44
55import numpy as np
66import pytest
@@ -360,6 +360,8 @@ def test_subtraction_ops_with_tz(self):
360360 ts_tz2 = Timestamp ("20130101" ).tz_localize ("CET" )
361361 dt_tz = ts_tz .to_pydatetime ()
362362 td = Timedelta ("1 days" )
363+ ts_utc = Timestamp ("2020-10-22T22:00:00+00:00" )
364+ dt_utc = datetime (2020 , 10 , 22 , 22 , tzinfo = timezone .utc )
363365
364366 def _check (result , expected ):
365367 assert result == expected
@@ -378,36 +380,54 @@ def _check(result, expected):
378380 expected = Timedelta ("0 days" )
379381 _check (result , expected )
380382
383+ result = ts_utc - dt_utc
384+ expected = Timedelta ("0 days" )
385+ _check (result , expected )
386+
387+ result = dt_tz - ts_tz2
388+ expected = Timedelta ("0 days 06:00:00" )
389+ _check (result , expected )
390+
391+ result = ts_tz2 - dt_tz
392+ expected = Timedelta ("-1 days +18:00:00" )
393+ _check (result , expected )
394+
395+ # gotta chedk this
381396 # tz mismatches
382- msg = "Timestamp subtraction must have the same timezones or no timezones "
397+ msg = "Cannot subtract offset-naive and offset-aware datetimes. "
383398 with pytest .raises (TypeError , match = msg ):
384399 dt_tz - ts
385400 msg = "can't subtract offset-naive and offset-aware datetimes"
386401 with pytest .raises (TypeError , match = msg ):
387402 dt_tz - dt
388- msg = "Timestamp subtraction must have the same timezones or no timezones"
389- with pytest .raises (TypeError , match = msg ):
390- dt_tz - ts_tz2
391403 msg = "can't subtract offset-naive and offset-aware datetimes"
392404 with pytest .raises (TypeError , match = msg ):
393405 dt - dt_tz
394- msg = "Timestamp subtraction must have the same timezones or no timezones "
406+ msg = "Cannot subtract offset-naive and offset-aware datetimes. "
395407 with pytest .raises (TypeError , match = msg ):
396408 ts - dt_tz
397409 with pytest .raises (TypeError , match = msg ):
398410 ts_tz2 - ts
399411 with pytest .raises (TypeError , match = msg ):
400412 ts_tz2 - dt
401- with pytest .raises (TypeError , match = msg ):
402- ts_tz - ts_tz2
403413
404414 # with dti
405415 with pytest .raises (TypeError , match = msg ):
406416 dti - ts_tz
407417 with pytest .raises (TypeError , match = msg ):
408418 dti_tz - ts
409- with pytest .raises (TypeError , match = msg ):
410- dti_tz - ts_tz2
419+
420+ result = dti_tz - ts_tz2
421+ expected = TimedeltaIndex (
422+ ["0 days 06:00:00" , "1 days 06:00:00" , "2 days 06:00:00" ]
423+ )
424+ tm .assert_index_equal (result , expected )
425+
426+ result = ts_tz2 - dti_tz
427+ expected = TimedeltaIndex (
428+ ["-1 days +18:00:00" , "-2 days +18:00:00" , "-3 days +18:00:00" ]
429+ )
430+ tm .assert_index_equal (result , expected )
411431
412432 result = dti_tz - dt_tz
413433 expected = TimedeltaIndex (["0 days" , "1 days" , "2 days" ])
0 commit comments