Add test for pandas deprecation warning

This commit is contained in:
Matthias
2024-01-14 13:56:02 +01:00
parent 5841c65430
commit 4aab57ce62
2 changed files with 29 additions and 2 deletions

View File

@@ -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

View File

@@ -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')