fix timestamp shift

This commit is contained in:
Kashif Rasul
2019-08-08 15:18:36 +02:00
parent 3092987917
commit 1d82ca94a8
+2 -5
View File
@@ -17,12 +17,9 @@ MAX_IDLE_TRANSFORMS = 100
def shift_timestamp(ts: pd.Timestamp, offset: int) -> pd.Timestamp:
try:
# this line looks innocent, but can create a date which is out of
# bounds values over year 9999 raise a ValueError
# bounds. Values over year 9999 raise a ValueError and
# values over 2262-04-11 raise a pandas OutOfBoundsDatetime
result = ts + offset * ts.freq
# For freq M and W pandas seems to lose the freq of the timestamp,
# so we explicitly set it.
return pd.Timestamp(result, freq=ts.freq)
return ts + offset * ts.freq
except (ValueError, pd._libs.OutOfBoundsDatetime) as ex:
raise Exception(ex)