From 393df83a9143e9c3d1dc640b335c6b6e6d14d005 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 14 Jan 2024 14:33:47 +0100 Subject: [PATCH] Implement enter_tag initialization to avoid futures warning --- freqtrade/strategy/interface.py | 5 ++++- tests/optimize/test_backtesting.py | 2 +- tests/optimize/test_backtesting_adjust_position.py | 2 +- tests/strategy/test_interface.py | 10 +++++----- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index bd846eb90..675e4a7c1 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -1388,7 +1388,8 @@ class IStrategy(ABC, HyperStrategyMixin): """ logger.debug(f"Populating enter signals for pair {metadata.get('pair')}.") - + # Initialize column to work around Pandas bug #56503. + dataframe.loc[:, 'enter_tag'] = '' df = self.populate_entry_trend(dataframe, metadata) if 'enter_long' not in df.columns: df = df.rename({'buy': 'enter_long', 'buy_tag': 'enter_tag'}, axis='columns') @@ -1404,6 +1405,8 @@ class IStrategy(ABC, HyperStrategyMixin): currently traded pair :return: DataFrame with exit column """ + # Initialize column to work around Pandas bug #56503. + dataframe.loc[:, 'exit_tag'] = '' logger.debug(f"Populating exit signals for pair {metadata.get('pair')}.") df = self.populate_exit_trend(dataframe, metadata) if 'exit_long' not in df.columns: diff --git a/tests/optimize/test_backtesting.py b/tests/optimize/test_backtesting.py index ca68724c9..87e92071f 100644 --- a/tests/optimize/test_backtesting.py +++ b/tests/optimize/test_backtesting.py @@ -734,7 +734,7 @@ def test_backtest_one(default_conf, fee, mocker, testdatadir) -> None: 'min_rate': [0.10370188, 0.10300000000000001], 'max_rate': [0.10501, 0.1038888], 'is_open': [False, False], - 'enter_tag': [None, None], + 'enter_tag': ['', ''], "leverage": [1.0, 1.0], "is_short": [False, False], 'open_timestamp': [1517251200000, 1517283000000], diff --git a/tests/optimize/test_backtesting_adjust_position.py b/tests/optimize/test_backtesting_adjust_position.py index 9b40b3a9d..56b04b3fd 100644 --- a/tests/optimize/test_backtesting_adjust_position.py +++ b/tests/optimize/test_backtesting_adjust_position.py @@ -72,7 +72,7 @@ def test_backtest_position_adjustment(default_conf, fee, mocker, testdatadir) -> 'min_rate': [0.10370188, 0.10300000000000001], 'max_rate': [0.10481985, 0.1038888], 'is_open': [False, False], - 'enter_tag': [None, None], + 'enter_tag': ['', ''], 'leverage': [1.0, 1.0], 'is_short': [False, False], 'open_timestamp': [1517251200000, 1517283000000], diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index 98e687268..790f5d255 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -1023,9 +1023,9 @@ def test_auto_hyperopt_interface_loadparams(default_conf, mocker, caplog): @pytest.mark.parametrize('function,raises', [ ('populate_entry_trend', True), - ('advise_entry', True), + ('advise_entry', False), ('populate_exit_trend', True), - ('advise_exit', True), + ('advise_exit', False), ]) def test_pandas_warning_direct(ohlcv_history, function, raises): @@ -1041,8 +1041,8 @@ def test_pandas_warning_direct(ohlcv_history, function, raises): getattr(_STRATEGY, function)(df, {'pair': 'ETH/BTC'}) -def test_pandas_warning_through_analyze_pair(ohlcv_history, mocker): +def test_pandas_warning_through_analyze_pair(ohlcv_history, mocker, recwarn): mocker.patch.object(_STRATEGY.dp, 'ohlcv', return_value=ohlcv_history) - with pytest.warns(FutureWarning): - _STRATEGY.analyze_pair('ETH/BTC') + _STRATEGY.analyze_pair('ETH/BTC') + assert len(recwarn) == 0