Skip to content

Commit

Permalink
handle missing timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
wgifford committed Oct 1, 2024
1 parent 079c098 commit 56a3024
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tsfm_public/toolkit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import numpy as np
import pandas as pd
import torch
from pandas.api.types import is_datetime64_dtype


def strtobool(val):
Expand Down Expand Up @@ -1150,10 +1151,19 @@ def convert_tsf(filename: str) -> pd.DataFrame:
else:
freq = None

# determine presence of timestamp column and name
default_start_timestamp = datetime(1900, 1, 1)
datetimes = [is_datetime64_dtype(d) for d in loaded_data.dtypes]
source_timestamp_column = None
if any(datetimes):
source_timestamp_column = loaded_data.columns[datetimes][0]

dfs = []
for index, item in loaded_data.iterrows():
if freq:
timestamps = pd.date_range(item.start_timestamp, periods=len(item.series_value), freq=freq)
if freq and source_timestamp_column:
timestamps = pd.date_range(item[source_timestamp_column], periods=len(item.series_value), freq=freq)
elif freq:
timestamps = pd.date_range(default_start_timestamp, periods=len(item.series_value), freq=freq)
else:
timestamps = range(len(item.series_value))

Expand Down

0 comments on commit 56a3024

Please sign in to comment.