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
@@ -337,6 +337,8 @@ def test_subtraction_ops_with_tz(self):
337337 ts_tz2 = Timestamp ("20130101" ).tz_localize ("CET" )
338338 dt_tz = ts_tz .to_pydatetime ()
339339 td = Timedelta ("1 days" )
340+ ts_utc = Timestamp ("2020-10-22T22:00:00+00:00" )
341+ dt_utc = datetime (2020 , 10 , 22 , 22 , tzinfo = timezone .utc )
340342
341343 def _check (result , expected ):
342344 assert result == expected
@@ -355,36 +357,51 @@ def _check(result, expected):
355357 expected = Timedelta ("0 days" )
356358 _check (result , expected )
357359
360+ result = ts_utc - dt_utc
361+ expected = Timedelta ("0 days" )
362+ _check (result , expected )
363+
364+ result = dt_tz - ts_tz2
365+ expected = Timedelta ("0 days 06:00:00" )
366+ _check (result , expected )
367+
368+ result = ts_tz2 - dt_tz
369+ expected = Timedelta ("-1 days +18:00:00" )
370+ _check (result , expected )
371+
372+ # gotta chedk this
358373 # tz mismatches
359- msg = "Timestamp subtraction must have the same timezones or no timezones "
374+ msg = "Cannot subtract offset-naive and offset-aware datetimes. "
360375 with pytest .raises (TypeError , match = msg ):
361376 dt_tz - ts
362377 msg = "can't subtract offset-naive and offset-aware datetimes"
363378 with pytest .raises (TypeError , match = msg ):
364379 dt_tz - dt
365- msg = "Timestamp subtraction must have the same timezones or no timezones"
366- with pytest .raises (TypeError , match = msg ):
367- dt_tz - ts_tz2
368380 msg = "can't subtract offset-naive and offset-aware datetimes"
369381 with pytest .raises (TypeError , match = msg ):
370382 dt - dt_tz
371- msg = "Timestamp subtraction must have the same timezones or no timezones "
383+ msg = "Cannot subtract offset-naive and offset-aware datetimes. "
372384 with pytest .raises (TypeError , match = msg ):
373385 ts - dt_tz
374386 with pytest .raises (TypeError , match = msg ):
375387 ts_tz2 - ts
376388 with pytest .raises (TypeError , match = msg ):
377389 ts_tz2 - dt
378- with pytest .raises (TypeError , match = msg ):
379- ts_tz - ts_tz2
380390
381391 # with dti
382392 with pytest .raises (TypeError , match = msg ):
383393 dti - ts_tz
384394 with pytest .raises (TypeError , match = msg ):
385395 dti_tz - ts
386- with pytest .raises (TypeError , match = msg ):
387- dti_tz - ts_tz2
396+
397+ result = dti_tz - ts_tz2
398+ expected = TimedeltaIndex (["0 days 06:00:00" , "1 days 06:00:00" , "2 days 06:00:00" ])
399+ tm .assert_index_equal (result , expected )
400+
401+
402+ result = ts_tz2 - dti_tz
403+ expected = TimedeltaIndex (["-1 days +18:00:00" , "-2 days +18:00:00" , "-3 days +18:00:00" ])
404+ tm .assert_index_equal (result , expected )
388405
389406 result = dti_tz - dt_tz
390407 expected = TimedeltaIndex (["0 days" , "1 days" , "2 days" ])
0 commit comments