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