From 926b01798138331877c6a004e8476e9af26f9dfa Mon Sep 17 00:00:00 2001 From: Joe Schr Date: Tue, 8 Feb 2022 16:42:39 +0100 Subject: [PATCH] Fix freqUI charts not displaying when dtype(datetime) column has NaT values fix dataframe_to_dict() issues by replacing NaT empty string and prepare for proper `.replace({NaT})` fix --- freqtrade/rpc/rpc.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 8e122d74d..97614a7b1 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -12,7 +12,7 @@ import psutil from dateutil.relativedelta import relativedelta from dateutil.tz import tzlocal from numpy import NAN, inf, int64, mean -from pandas import DataFrame +from pandas import DataFrame, NaT, isnull from freqtrade import __version__ from freqtrade.configuration.timerange import TimeRange @@ -963,6 +963,24 @@ class RPC: sell_mask = (dataframe['sell'] == 1) sell_signals = int(sell_mask.sum()) dataframe.loc[sell_mask, '_sell_signal_close'] = dataframe.loc[sell_mask, 'close'] + """ + band-aid until this is fixed: + https://github.com/pandas-dev/pandas/issues/45836 + """ + datetime_types = ['datetime', 'datetime64', 'datetime64[ns, UTC]'] + date_columns = dataframe.select_dtypes(include=datetime_types) + for date_column in date_columns: + # replace NaT with empty string, + # because if replaced with `None` + # it will be casted into NaT again + dataframe[date_column] = dataframe[date_column].apply( + lambda x: '' if isnull(x) else x) + + """ + try this if above pandas Issue#45836 is fixed: + https://github.com/pandas-dev/pandas/issues/45836 + """ + # dataframe = dataframe.replace({NaT: None}) dataframe = dataframe.replace([inf, -inf], NAN) dataframe = dataframe.replace({NAN: None})