@@ -914,11 +914,22 @@ def test_addsub_offset(self, ts_tz):
914
914
assert result .month == 12
915
915
assert tz_compare (result .tz , ts_tz .tz )
916
916
917
+ result = ts_tz - off
918
+
919
+ assert isinstance (result , Timestamp )
920
+ assert result ._reso == ts_tz ._reso
921
+ assert result .year == ts_tz .year - 1
922
+ assert result .day == 31
923
+ assert result .month == 12
924
+ assert tz_compare (result .tz , ts_tz .tz )
925
+
917
926
def test_sub_datetimelike_mismatched_reso (self , ts_tz ):
918
927
# case with non-lossy rounding
919
928
ts = ts_tz
920
929
921
- # choose a unit for `other` that doesn't match ts_tz's
930
+ # choose a unit for `other` that doesn't match ts_tz's;
931
+ # this construction ensures we get cases with other._reso < ts._reso
932
+ # and cases with other._reso > ts._reso
922
933
unit = {
923
934
NpyDatetimeUnit .NPY_FR_us .value : "ms" ,
924
935
NpyDatetimeUnit .NPY_FR_ms .value : "s" ,
@@ -937,8 +948,7 @@ def test_sub_datetimelike_mismatched_reso(self, ts_tz):
937
948
assert result .value == 0
938
949
assert result ._reso == min (ts ._reso , other ._reso )
939
950
940
- # TODO: clarify in message that add/sub is allowed only when lossless?
941
- msg = "Cannot losslessly convert units"
951
+ msg = "Timestamp subtraction with mismatched resolutions"
942
952
if ts ._reso < other ._reso :
943
953
# Case where rounding is lossy
944
954
other2 = other + Timedelta ._from_value_and_reso (1 , other ._reso )
0 commit comments