feat: add error in case of non-available informative dataframe

This commit is contained in:
Matthias
2025-09-06 09:38:23 +02:00
parent 246891a8f6
commit 816ca2ea15
2 changed files with 18 additions and 3 deletions

View File

@@ -133,6 +133,11 @@ def _create_and_merge_informative_pair(
inf_metadata = {"pair": asset, "timeframe": timeframe}
inf_dataframe = strategy.dp.get_pair_dataframe(asset, timeframe, candle_type)
if inf_dataframe.empty:
raise ValueError(
f"Informative dataframe for ({asset}, {timeframe}, {candle_type}) is empty. "
"Can't populate informative indicators."
)
inf_dataframe = populate_indicators_fn(strategy, inf_dataframe, inf_metadata)
formatter: Any = None

View File

@@ -380,9 +380,10 @@ def test_informative_decorator(mocker, default_conf_usdt, trading_mode):
assert inf_pair in strategy.gather_informative_pairs()
def test_historic_ohlcv(pair, timeframe, candle_type):
return data[
(pair, timeframe or strategy.timeframe, CandleType.from_string(candle_type))
].copy()
return data.get(
(pair, timeframe or strategy.timeframe, CandleType.from_string(candle_type)),
pd.DataFrame(),
).copy()
mocker.patch(
"freqtrade.data.dataprovider.DataProvider.historic_ohlcv", side_effect=test_historic_ohlcv
@@ -405,3 +406,12 @@ def test_informative_decorator(mocker, default_conf_usdt, trading_mode):
for _, dataframe in analyzed.items():
for col in expected_columns:
assert col in dataframe.columns
# Test non-available pairs
del data[("ETH/BTC", "1h", CandleType.SPOT)]
with pytest.raises(
ValueError, match=r"Informative dataframe for \(ETH\/BTC, 1h, spot\) is empty.*"
):
strategy.advise_all_indicators(
{p: data[(p, strategy.timeframe, candle_def)] for p in ("XRP/USDT", "LTC/USDT")}
)