@@ -843,6 +843,61 @@ def test_dt64arr_sub_timedeltalike_scalar(
843
843
rng -= two_hours
844
844
tm .assert_equal (rng , expected )
845
845
846
+ def test_dt64_array_sub_dt_with_different_timezone (self , box_with_array ):
847
+ t1 = date_range ("20130101" , periods = 3 ).tz_localize ("US/Eastern" )
848
+ t1 = tm .box_expected (t1 , box_with_array )
849
+ t2 = Timestamp ("20130101" ).tz_localize ("CET" )
850
+ tnaive = Timestamp (20130101 )
851
+
852
+ result = t1 - t2
853
+ expected = TimedeltaIndex (
854
+ ["0 days 06:00:00" , "1 days 06:00:00" , "2 days 06:00:00" ]
855
+ )
856
+ expected = tm .box_expected (expected , box_with_array )
857
+ tm .assert_equal (result , expected )
858
+
859
+ result = t2 - t1
860
+ expected = TimedeltaIndex (
861
+ ["-1 days +18:00:00" , "-2 days +18:00:00" , "-3 days +18:00:00" ]
862
+ )
863
+ expected = tm .box_expected (expected , box_with_array )
864
+ tm .assert_equal (result , expected )
865
+
866
+ msg = "Cannot subtract tz-naive and tz-aware datetime-like objects"
867
+ with pytest .raises (TypeError , match = msg ):
868
+ t1 - tnaive
869
+
870
+ with pytest .raises (TypeError , match = msg ):
871
+ tnaive - t1
872
+
873
+ def test_dt64_array_sub_dt64_array_with_different_timezone (self , box_with_array ):
874
+ t1 = date_range ("20130101" , periods = 3 ).tz_localize ("US/Eastern" )
875
+ t1 = tm .box_expected (t1 , box_with_array )
876
+ t2 = date_range ("20130101" , periods = 3 ).tz_localize ("CET" )
877
+ t2 = tm .box_expected (t2 , box_with_array )
878
+ tnaive = date_range ("20130101" , periods = 3 )
879
+
880
+ result = t1 - t2
881
+ expected = TimedeltaIndex (
882
+ ["0 days 06:00:00" , "0 days 06:00:00" , "0 days 06:00:00" ]
883
+ )
884
+ expected = tm .box_expected (expected , box_with_array )
885
+ tm .assert_equal (result , expected )
886
+
887
+ result = t2 - t1
888
+ expected = TimedeltaIndex (
889
+ ["-1 days +18:00:00" , "-1 days +18:00:00" , "-1 days +18:00:00" ]
890
+ )
891
+ expected = tm .box_expected (expected , box_with_array )
892
+ tm .assert_equal (result , expected )
893
+
894
+ msg = "Cannot subtract tz-naive and tz-aware datetime-like objects"
895
+ with pytest .raises (TypeError , match = msg ):
896
+ t1 - tnaive
897
+
898
+ with pytest .raises (TypeError , match = msg ):
899
+ tnaive - t1
900
+
846
901
# TODO: redundant with test_dt64arr_add_timedeltalike_scalar
847
902
def test_dt64arr_add_td64_scalar (self , box_with_array ):
848
903
# scalar timedeltas/np.timedelta64 objects
@@ -1024,7 +1079,7 @@ def test_dt64arr_aware_sub_dt64ndarray_raises(
1024
1079
dt64vals = dti .values
1025
1080
1026
1081
dtarr = tm .box_expected (dti , box_with_array )
1027
- msg = "subtraction must have the same timezones or "
1082
+ msg = "Cannot subtract tz-naive and tz-aware datetime "
1028
1083
with pytest .raises (TypeError , match = msg ):
1029
1084
dtarr - dt64vals
1030
1085
with pytest .raises (TypeError , match = msg ):
@@ -2208,24 +2263,20 @@ def test_sub_dti_dti(self):
2208
2263
2209
2264
dti = date_range ("20130101" , periods = 3 )
2210
2265
dti_tz = date_range ("20130101" , periods = 3 ).tz_localize ("US/Eastern" )
2211
- dti_tz2 = date_range ("20130101" , periods = 3 ).tz_localize ("UTC" )
2212
2266
expected = TimedeltaIndex ([0 , 0 , 0 ])
2213
2267
2214
2268
result = dti - dti
2215
2269
tm .assert_index_equal (result , expected )
2216
2270
2217
2271
result = dti_tz - dti_tz
2218
2272
tm .assert_index_equal (result , expected )
2219
- msg = "DatetimeArray subtraction must have the same timezones or "
2273
+ msg = "Cannot subtract tz-naive and tz-aware datetime-like objects "
2220
2274
with pytest .raises (TypeError , match = msg ):
2221
2275
dti_tz - dti
2222
2276
2223
2277
with pytest .raises (TypeError , match = msg ):
2224
2278
dti - dti_tz
2225
2279
2226
- with pytest .raises (TypeError , match = msg ):
2227
- dti_tz - dti_tz2
2228
-
2229
2280
# isub
2230
2281
dti -= dti
2231
2282
tm .assert_index_equal (dti , expected )
0 commit comments