Merge pull request #6340 from TheJoeSchr/frequi-datetime

freqUI: fix can't import backtest with missing datetime data
This commit is contained in:
Matthias
2022-02-09 07:21:30 +01:00
committed by GitHub
2 changed files with 32 additions and 3 deletions

View File

@@ -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
from freqtrade import __version__
from freqtrade.configuration.timerange import TimeRange
@@ -963,8 +963,18 @@ 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']
dataframe = dataframe.replace([inf, -inf], NAN)
dataframe = dataframe.replace({NAN: None})
# 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].astype(object).replace({NaT: None})
dataframe = dataframe.replace({inf: None, -inf: None, NAN: None})
res = {
'pair': pair,