From 29e5f7ee86529ed2c3dbadf234043388c11ea548 Mon Sep 17 00:00:00 2001 From: Dale Jung Date: Wed, 25 Feb 2015 09:15:14 -0500 Subject: [PATCH] PRF: Added nanmean, nanstd, nansum that will default to bottleneck if available --- zipline/utils/math_utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zipline/utils/math_utils.py b/zipline/utils/math_utils.py index 647ac0b6..43e4d380 100644 --- a/zipline/utils/math_utils.py +++ b/zipline/utils/math_utils.py @@ -14,7 +14,22 @@ # limitations under the License. import math +import numpy as np def tolerant_equals(a, b, atol=10e-7, rtol=10e-7): return math.fabs(a - b) <= (atol + rtol * math.fabs(b)) + + +nanmean = np.nanmean +nanstd = np.nanstd +nansum = np.nansum + + +try: + import bottleneck as bn + nanmean = bn.nanmean + nanstd = bn.nanstd + nansum = bn.nansum +except ImportError: + pass