From 1d82ca94a85fee0b34e88c6222f01a9840ea6784 Mon Sep 17 00:00:00 2001 From: Kashif Rasul Date: Thu, 8 Aug 2019 15:18:36 +0200 Subject: [PATCH] fix timestamp shift --- pts/feature/transform.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pts/feature/transform.py b/pts/feature/transform.py index 5cfc518..a0ad935 100644 --- a/pts/feature/transform.py +++ b/pts/feature/transform.py @@ -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)