@@ -845,6 +845,61 @@ def test_dt64arr_isub_timedeltalike_scalar(
845
845
rng -= two_hours
846
846
tm .assert_equal (rng , expected )
847
847
848
+ def test_dt64_array_sub_dt_with_different_timezone (self , box_with_array ):
849
+ t1 = date_range ("20130101" , periods = 3 ).tz_localize ("US/Eastern" )
850
+ t1 = tm .box_expected (t1 , box_with_array )
851
+ t2 = Timestamp ("20130101" ).tz_localize ("CET" )
852
+ tnaive = Timestamp (20130101 )
853
+
854
+ result = t1 - t2
855
+ expected = TimedeltaIndex (
856
+ ["0 days 06:00:00" , "1 days 06:00:00" , "2 days 06:00:00" ]
857
+ )
858
+ expected = tm .box_expected (expected , box_with_array )
859
+ tm .assert_equal (result , expected )
860
+
861
+ result = t2 - t1
862
+ expected = TimedeltaIndex (
863
+ ["-1 days +18:00:00" , "-2 days +18:00:00" , "-3 days +18:00:00" ]
864
+ )
865
+ expected = tm .box_expected (expected , box_with_array )
866
+ tm .assert_equal (result , expected )
867
+
868
+ msg = "Cannot subtract tz-naive and tz-aware datetime-like objects"
869
+ with pytest .raises (TypeError , match = msg ):
870
+ t1 - tnaive
871
+
872
+ with pytest .raises (TypeError , match = msg ):
873
+ tnaive - t1
874
+
875
+ def test_dt64_array_sub_dt64_array_with_different_timezone (self , box_with_array ):
876
+ t1 = date_range ("20130101" , periods = 3 ).tz_localize ("US/Eastern" )
877
+ t1 = tm .box_expected (t1 , box_with_array )
878
+ t2 = date_range ("20130101" , periods = 3 ).tz_localize ("CET" )
879
+ t2 = tm .box_expected (t2 , box_with_array )
880
+ tnaive = date_range ("20130101" , periods = 3 )
881
+
882
+ result = t1 - t2
883
+ expected = TimedeltaIndex (
884
+ ["0 days 06:00:00" , "0 days 06:00:00" , "0 days 06:00:00" ]
885
+ )
886
+ expected = tm .box_expected (expected , box_with_array )
887
+ tm .assert_equal (result , expected )
888
+
889
+ result = t2 - t1
890
+ expected = TimedeltaIndex (
891
+ ["-1 days +18:00:00" , "-1 days +18:00:00" , "-1 days +18:00:00" ]
892
+ )
893
+ expected = tm .box_expected (expected , box_with_array )
894
+ tm .assert_equal (result , expected )
895
+
896
+ msg = "Cannot subtract tz-naive and tz-aware datetime-like objects"
897
+ with pytest .raises (TypeError , match = msg ):
898
+ t1 - tnaive
899
+
900
+ with pytest .raises (TypeError , match = msg ):
901
+ tnaive - t1
902
+
848
903
# TODO: redundant with test_dt64arr_add_timedeltalike_scalar
849
904
def test_dt64arr_add_td64_scalar (self , box_with_array ):
850
905
# scalar timedeltas/np.timedelta64 objects
@@ -1026,7 +1081,7 @@ def test_dt64arr_aware_sub_dt64ndarray_raises(
1026
1081
dt64vals = dti .values
1027
1082
1028
1083
dtarr = tm .box_expected (dti , box_with_array )
1029
- msg = "subtraction must have the same timezones or "
1084
+ msg = "Cannot subtract tz-naive and tz-aware datetime "
1030
1085
with pytest .raises (TypeError , match = msg ):
1031
1086
dtarr - dt64vals
1032
1087
with pytest .raises (TypeError , match = msg ):
@@ -2223,24 +2278,20 @@ def test_sub_dti_dti(self):
2223
2278
2224
2279
dti = date_range ("20130101" , periods = 3 )
2225
2280
dti_tz = date_range ("20130101" , periods = 3 ).tz_localize ("US/Eastern" )
2226
- dti_tz2 = date_range ("20130101" , periods = 3 ).tz_localize ("UTC" )
2227
2281
expected = TimedeltaIndex ([0 , 0 , 0 ])
2228
2282
2229
2283
result = dti - dti
2230
2284
tm .assert_index_equal (result , expected )
2231
2285
2232
2286
result = dti_tz - dti_tz
2233
2287
tm .assert_index_equal (result , expected )
2234
- msg = "DatetimeArray subtraction must have the same timezones or "
2288
+ msg = "Cannot subtract tz-naive and tz-aware datetime-like objects "
2235
2289
with pytest .raises (TypeError , match = msg ):
2236
2290
dti_tz - dti
2237
2291
2238
2292
with pytest .raises (TypeError , match = msg ):
2239
2293
dti - dti_tz
2240
2294
2241
- with pytest .raises (TypeError , match = msg ):
2242
- dti_tz - dti_tz2
2243
-
2244
2295
# isub
2245
2296
dti -= dti
2246
2297
tm .assert_index_equal (dti , expected )
0 commit comments