@@ -859,6 +859,61 @@ def test_dt64arr_isub_timedeltalike_scalar(
859
859
rng -= two_hours
860
860
tm .assert_equal (rng , expected )
861
861
862
+ def test_dt64_array_sub_dt_with_different_timezone (self , box_with_array ):
863
+ t1 = date_range ("20130101" , periods = 3 ).tz_localize ("US/Eastern" )
864
+ t1 = tm .box_expected (t1 , box_with_array )
865
+ t2 = Timestamp ("20130101" ).tz_localize ("CET" )
866
+ tnaive = Timestamp (20130101 )
867
+
868
+ result = t1 - t2
869
+ expected = TimedeltaIndex (
870
+ ["0 days 06:00:00" , "1 days 06:00:00" , "2 days 06:00:00" ]
871
+ )
872
+ expected = tm .box_expected (expected , box_with_array )
873
+ tm .assert_equal (result , expected )
874
+
875
+ result = t2 - t1
876
+ expected = TimedeltaIndex (
877
+ ["-1 days +18:00:00" , "-2 days +18:00:00" , "-3 days +18:00:00" ]
878
+ )
879
+ expected = tm .box_expected (expected , box_with_array )
880
+ tm .assert_equal (result , expected )
881
+
882
+ msg = "Cannot subtract tz-naive and tz-aware datetime-like objects"
883
+ with pytest .raises (TypeError , match = msg ):
884
+ t1 - tnaive
885
+
886
+ with pytest .raises (TypeError , match = msg ):
887
+ tnaive - t1
888
+
889
+ def test_dt64_array_sub_dt64_array_with_different_timezone (self , box_with_array ):
890
+ t1 = date_range ("20130101" , periods = 3 ).tz_localize ("US/Eastern" )
891
+ t1 = tm .box_expected (t1 , box_with_array )
892
+ t2 = date_range ("20130101" , periods = 3 ).tz_localize ("CET" )
893
+ t2 = tm .box_expected (t2 , box_with_array )
894
+ tnaive = date_range ("20130101" , periods = 3 )
895
+
896
+ result = t1 - t2
897
+ expected = TimedeltaIndex (
898
+ ["0 days 06:00:00" , "0 days 06:00:00" , "0 days 06:00:00" ]
899
+ )
900
+ expected = tm .box_expected (expected , box_with_array )
901
+ tm .assert_equal (result , expected )
902
+
903
+ result = t2 - t1
904
+ expected = TimedeltaIndex (
905
+ ["-1 days +18:00:00" , "-1 days +18:00:00" , "-1 days +18:00:00" ]
906
+ )
907
+ expected = tm .box_expected (expected , box_with_array )
908
+ tm .assert_equal (result , expected )
909
+
910
+ msg = "Cannot subtract tz-naive and tz-aware datetime-like objects"
911
+ with pytest .raises (TypeError , match = msg ):
912
+ t1 - tnaive
913
+
914
+ with pytest .raises (TypeError , match = msg ):
915
+ tnaive - t1
916
+
862
917
# TODO: redundant with test_dt64arr_add_timedeltalike_scalar
863
918
def test_dt64arr_add_td64_scalar (self , box_with_array ):
864
919
# scalar timedeltas/np.timedelta64 objects
@@ -1040,7 +1095,7 @@ def test_dt64arr_aware_sub_dt64ndarray_raises(
1040
1095
dt64vals = dti .values
1041
1096
1042
1097
dtarr = tm .box_expected (dti , box_with_array )
1043
- msg = "subtraction must have the same timezones or "
1098
+ msg = "Cannot subtract tz-naive and tz-aware datetime "
1044
1099
with pytest .raises (TypeError , match = msg ):
1045
1100
dtarr - dt64vals
1046
1101
with pytest .raises (TypeError , match = msg ):
@@ -2237,24 +2292,20 @@ def test_sub_dti_dti(self):
2237
2292
2238
2293
dti = date_range ("20130101" , periods = 3 )
2239
2294
dti_tz = date_range ("20130101" , periods = 3 ).tz_localize ("US/Eastern" )
2240
- dti_tz2 = date_range ("20130101" , periods = 3 ).tz_localize ("UTC" )
2241
2295
expected = TimedeltaIndex ([0 , 0 , 0 ])
2242
2296
2243
2297
result = dti - dti
2244
2298
tm .assert_index_equal (result , expected )
2245
2299
2246
2300
result = dti_tz - dti_tz
2247
2301
tm .assert_index_equal (result , expected )
2248
- msg = "DatetimeArray subtraction must have the same timezones or "
2302
+ msg = "Cannot subtract tz-naive and tz-aware datetime-like objects "
2249
2303
with pytest .raises (TypeError , match = msg ):
2250
2304
dti_tz - dti
2251
2305
2252
2306
with pytest .raises (TypeError , match = msg ):
2253
2307
dti - dti_tz
2254
2308
2255
- with pytest .raises (TypeError , match = msg ):
2256
- dti_tz - dti_tz2
2257
-
2258
2309
# isub
2259
2310
dti -= dti
2260
2311
tm .assert_index_equal (dti , expected )
0 commit comments