diff --git a/nbs/timegpt.ipynb b/nbs/timegpt.ipynb index 673fb095..f682305e 100644 --- a/nbs/timegpt.ipynb +++ b/nbs/timegpt.ipynb @@ -259,6 +259,14 @@ " df.index.name = time_col\n", " df = df.reset_index()\n", " else:\n", + " if hasattr(df.index, \"name\"):\n", + " if df.index.name == self.time_col:\n", + " try:\n", + " df.index = pd.to_datetime(df.index)\n", + " main_logger.info(\"Using datetime index as time column\")\n", + " except:\n", + " raise ValueError(f\"Dataframe index {self.time_col} is not of date type\")\n", + " df=df.reset_index()\n", " self.freq = self.base_freq\n", " renamer = {\n", " self.id_col: 'unique_id',\n", diff --git a/nixtlats/timegpt.py b/nixtlats/timegpt.py index 71f1dcd6..427c0cff 100644 --- a/nixtlats/timegpt.py +++ b/nixtlats/timegpt.py @@ -197,6 +197,16 @@ def transform_inputs(self, df: pd.DataFrame, X_df: pd.DataFrame): df.index.name = time_col df = df.reset_index() else: + if hasattr(df.index, "name"): + if df.index.name == self.time_col: + try: + df.index = pd.to_datetime(df.index) + main_logger.info("Using datetime index as time column") + except: + raise ValueError( + f"Dataframe index {self.time_col} is not of date type" + ) + df = df.reset_index() self.freq = self.base_freq renamer = { self.id_col: "unique_id",