From 8b5e6bf9be6c5d2897bb9672304bd306095046a1 Mon Sep 17 00:00:00 2001 From: robcaulk Date: Mon, 4 Dec 2023 16:23:55 +0100 Subject: [PATCH] chore: fix pandas warning about merging on datetime. fix pandas warning about inconsistent key lists in concat --- freqtrade/freqai/data_drawer.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/freqtrade/freqai/data_drawer.py b/freqtrade/freqai/data_drawer.py index f8b8f0de4..afd70c300 100644 --- a/freqtrade/freqai/data_drawer.py +++ b/freqtrade/freqai/data_drawer.py @@ -284,6 +284,10 @@ class FreqaiDataDrawer: new_pred["date_pred"] = dataframe["date"] hist_preds = self.historic_predictions[pair].copy() + # ensure both dataframes have the same date format so they can be merged + new_pred["date_pred"] = pd.to_datetime(new_pred["date_pred"], utc=True) + hist_preds["date_pred"] = pd.to_datetime(hist_preds["date_pred"], utc=True) + # find the closest common date between new_pred and historic predictions # and cut off the new_pred dataframe at that date common_dates = pd.merge(new_pred, hist_preds, on="date_pred", how="inner") @@ -294,7 +298,9 @@ class FreqaiDataDrawer: "predictions. You likely left your FreqAI instance offline " f"for more than {len(dataframe.index)} candles.") - df_concat = pd.concat([hist_preds, new_pred], ignore_index=True, keys=hist_preds.keys()) + # reindex new_pred columns to match the historic predictions dataframe + new_pred_reindexed = new_pred.reindex(columns=hist_preds.columns) + df_concat = pd.concat([hist_preds, new_pred_reindexed], ignore_index=True) # any missing values will get zeroed out so users can see the exact # downtime in FreqUI