mirror of
https://github.com/wassname/pytorch-ts.git
synced 2026-07-17 11:32:26 +08:00
fix timestamp shift
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user