From 4aab57ce6235185a4b9aedd725dbd9e8a8345759 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 14 Jan 2024 13:56:02 +0100 Subject: [PATCH] Add test for pandas deprecation warning --- tests/strategy/strats/strategy_test_v3.py | 4 ++-- tests/strategy/test_interface.py | 27 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/strategy/strats/strategy_test_v3.py b/tests/strategy/strats/strategy_test_v3.py index 571427fb1..83c7353ce 100644 --- a/tests/strategy/strats/strategy_test_v3.py +++ b/tests/strategy/strats/strategy_test_v3.py @@ -152,7 +152,7 @@ class StrategyTestV3(IStrategy): ( qtpylib.crossed_below(dataframe['rsi'], self.sell_rsi.value) ), - 'enter_short'] = 1 + ('enter_short', 'enter_tag')] = (1, 'short_Tag') return dataframe @@ -176,7 +176,7 @@ class StrategyTestV3(IStrategy): ( qtpylib.crossed_above(dataframe['rsi'], self.buy_rsi.value) ), - 'exit_short'] = 1 + ('exit_short', 'exit_tag')] = (1, 'short_Tag') return dataframe diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index d17b9a72f..98e687268 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -1019,3 +1019,30 @@ def test_auto_hyperopt_interface_loadparams(default_conf, mocker, caplog): StrategyResolver.load_strategy(default_conf) assert log_has("Invalid parameter file format.", caplog) + + +@pytest.mark.parametrize('function,raises', [ + ('populate_entry_trend', True), + ('advise_entry', True), + ('populate_exit_trend', True), + ('advise_exit', True), +]) +def test_pandas_warning_direct(ohlcv_history, function, raises): + + df = _STRATEGY.populate_indicators(ohlcv_history, {'pair': 'ETH/BTC'}) + if raises: + with pytest.warns(FutureWarning): + # Test for Future warning + # FutureWarning: Setting an item of incompatible dtype is + # deprecated and will raise in a future error of pandas + # https://github.com/pandas-dev/pandas/issues/56503 + getattr(_STRATEGY, function)(df, {'pair': 'ETH/BTC'}) + else: + getattr(_STRATEGY, function)(df, {'pair': 'ETH/BTC'}) + + +def test_pandas_warning_through_analyze_pair(ohlcv_history, mocker): + + mocker.patch.object(_STRATEGY.dp, 'ohlcv', return_value=ohlcv_history) + with pytest.warns(FutureWarning): + _STRATEGY.analyze_pair('ETH/BTC')