From 9d4ecb625a004a45dc58c0f942394f0f4b80d277 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 26 Aug 2020 07:16:29 +0200 Subject: [PATCH] Allow numpy numbers as comparisons, too --- freqtrade/vendor/qtpylib/indicators.py | 2 +- tests/test_indicators.py | 18 ++++++++++++++++++ tests/test_talib.py | 2 -- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/test_indicators.py diff --git a/freqtrade/vendor/qtpylib/indicators.py b/freqtrade/vendor/qtpylib/indicators.py index bef140396..e5a404862 100644 --- a/freqtrade/vendor/qtpylib/indicators.py +++ b/freqtrade/vendor/qtpylib/indicators.py @@ -222,7 +222,7 @@ def crossed(series1, series2, direction=None): if isinstance(series1, np.ndarray): series1 = pd.Series(series1) - if isinstance(series2, (float, int, np.ndarray)): + if isinstance(series2, (float, int, np.ndarray, np.integer, np.floating)): series2 = pd.Series(index=series1.index, data=series2) if direction is None or direction == "above": diff --git a/tests/test_indicators.py b/tests/test_indicators.py new file mode 100644 index 000000000..2f9bdc0f9 --- /dev/null +++ b/tests/test_indicators.py @@ -0,0 +1,18 @@ +import freqtrade.vendor.qtpylib.indicators as qtpylib +import numpy as np +import pandas as pd + + +def test_crossed_numpy_types(): + """ + This test is only present since this method currently diverges from the qtpylib implementation. + And we must ensure to not break this again once we update from the original source. + """ + series = pd.Series([56, 97, 19, 76, 65, 25, 87, 91, 79, 79]) + expected_result = pd.Series([False, True, False, True, False, False, True, False, False, False]) + + assert qtpylib.crossed_above(series, 60).equals(expected_result) + assert qtpylib.crossed_above(series, 60.0).equals(expected_result) + assert qtpylib.crossed_above(series, np.int32(60)).equals(expected_result) + assert qtpylib.crossed_above(series, np.int64(60)).equals(expected_result) + assert qtpylib.crossed_above(series, np.float64(60.0)).equals(expected_result) diff --git a/tests/test_talib.py b/tests/test_talib.py index 2c7f73eb1..4effc129b 100644 --- a/tests/test_talib.py +++ b/tests/test_talib.py @@ -1,5 +1,3 @@ - - import talib.abstract as ta import pandas as pd