From 080fc318ebf5de0e0cf9686ddfc9737195521a1e Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 26 Aug 2020 06:59:04 +0200 Subject: [PATCH 1/2] Allow crossed() methods with np.integer types Fixes bad behaviour when passing in a np.integer type instead of a regular integer `crossed_above(series, 25)` does work, while `crossed_above(series, np.int64(25))` does not work. On it's own, this is not a problem, however, it can become a problem depending where the 2nd variable came from. --- qtpylib/indicators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtpylib/indicators.py b/qtpylib/indicators.py index 32d6315..3e641e1 100644 --- a/qtpylib/indicators.py +++ b/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)): series2 = pd.Series(index=series1.index, data=series2) if direction is None or direction == "above": From 3eacbfad8aa167adfcefb98b95722a5ac4d1f2b8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 26 Aug 2020 07:02:04 +0200 Subject: [PATCH 2/2] Add np.floating to also support np.float64 types --- qtpylib/indicators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qtpylib/indicators.py b/qtpylib/indicators.py index 3e641e1..47752fc 100644 --- a/qtpylib/indicators.py +++ b/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, np.integer)): + 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":