From bd98637ae934db16968d921f560e9a05a04b1549 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 30 Dec 2021 10:14:45 +0100 Subject: [PATCH] Fail gracefully from plot-profit when no data is provided closes #6132 --- freqtrade/data/btanalysis.py | 1 + freqtrade/plot/plotting.py | 7 ++++++- tests/data/test_btanalysis.py | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index 7d97661c4..560dd42f1 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -325,6 +325,7 @@ def combine_dataframes_with_mean(data: Dict[str, pd.DataFrame], :param column: Column in the original dataframes to use :return: DataFrame with the column renamed to the dict key, and a column named mean, containing the mean of all pairs. + :raise: ValueError if no data is provided. """ df_comb = pd.concat([data[pair].set_index('date').rename( {column: pair}, axis=1)[pair] for pair in data], axis=1) diff --git a/freqtrade/plot/plotting.py b/freqtrade/plot/plotting.py index 6d44d56b1..fd5317e27 100644 --- a/freqtrade/plot/plotting.py +++ b/freqtrade/plot/plotting.py @@ -460,7 +460,12 @@ def generate_candlestick_graph(pair: str, data: pd.DataFrame, trades: pd.DataFra def generate_profit_graph(pairs: str, data: Dict[str, pd.DataFrame], trades: pd.DataFrame, timeframe: str, stake_currency: str) -> go.Figure: # Combine close-values for all pairs, rename columns to "pair" - df_comb = combine_dataframes_with_mean(data, "close") + try: + df_comb = combine_dataframes_with_mean(data, "close") + except ValueError: + raise OperationalException( + "No data found. Please make sure that data is available for " + "the timerange and pairs selected.") # Trim trades to available OHLCV data trades = extract_trades_of_period(df_comb, trades, date_index=True) diff --git a/tests/data/test_btanalysis.py b/tests/data/test_btanalysis.py index 1dcd04a80..b06dfce0a 100644 --- a/tests/data/test_btanalysis.py +++ b/tests/data/test_btanalysis.py @@ -234,6 +234,13 @@ def test_combine_dataframes_with_mean(testdatadir): assert "mean" in df.columns +def test_combine_dataframes_with_mean_no_data(testdatadir): + pairs = ["ETH/BTC", "ADA/BTC"] + data = load_data(datadir=testdatadir, pairs=pairs, timeframe='6m') + with pytest.raises(ValueError, match=r"No objects to concatenate"): + combine_dataframes_with_mean(data) + + def test_create_cum_profit(testdatadir): filename = testdatadir / "backtest-result_test.json" bt_data = load_backtest_data(filename)