Don't hard-fail merge if there's no informative data

This commit is contained in:
Matthias
2023-09-10 16:16:52 +02:00
parent 21859f79db
commit 563e68e894
2 changed files with 31 additions and 4 deletions

View File

@@ -45,10 +45,13 @@ def merge_informative_pair(dataframe: pd.DataFrame, informative: pd.DataFrame,
elif minutes < minutes_inf:
# Subtract "small" timeframe so merging is not delayed by 1 small candle
# Detailed explanation in https://github.com/freqtrade/freqtrade/issues/4073
informative['date_merge'] = (
informative[date_column] + pd.to_timedelta(minutes_inf, 'm') -
pd.to_timedelta(minutes, 'm')
)
if not informative.empty:
informative['date_merge'] = (
informative[date_column] + pd.to_timedelta(minutes_inf, 'm') -
pd.to_timedelta(minutes, 'm')
)
else:
informative['date_merge'] = informative[date_column]
else:
raise ValueError("Tried to merge a faster timeframe to a slower timeframe."
"This would create new rows, and can throw off your regular indicators.")

View File

@@ -96,6 +96,30 @@ def test_merge_informative_pair_lower():
merge_informative_pair(data, informative, '1h', '15m', ffill=True)
def test_merge_informative_pair_empty():
data = generate_test_data('1h', 40)
informative = pd.DataFrame(columns=data.columns)
result = merge_informative_pair(data, informative, '1h', '2h', ffill=True)
assert result['date'].equals(data['date'])
assert list(result.columns) == [
'date',
'open',
'high',
'low',
'close',
'volume',
'date_2h',
'open_2h',
'high_2h',
'low_2h',
'close_2h',
'volume_2h'
]
assert result['volume_2h'].isnull().all()
def test_merge_informative_pair_suffix():
data = generate_test_data('15m', 20)
informative = generate_test_data('1h', 20)