diff --git a/zipline/modelling/expression.py b/zipline/modelling/expression.py index 63568135..cc78906f 100644 --- a/zipline/modelling/expression.py +++ b/zipline/modelling/expression.py @@ -3,6 +3,7 @@ NumericalExpression term. """ from itertools import chain import re +from numbers import Number import numexpr from numexpr.necompiler import getExprNames @@ -10,7 +11,6 @@ from numpy import ( empty, find_common_type, ) -from six import integer_types from zipline.modelling.term import Term, NotSpecified @@ -58,7 +58,6 @@ MATH_BINOPS = {'+', '-', '*', '/', '**', '%'} FILTER_BINOPS = {'&', '|'} # NumExpr doesn't support xor. COMPARISONS = {'<', '<=', '!=', '>=', '>', '=='} -NUMERIC_TYPES = (float,) + integer_types NUMEXPR_MATH_FUNCS = { 'sin', 'cos', @@ -284,7 +283,7 @@ class NumericalExpression(Term): self_expr = self._expr new_inputs, other_idx = _ensure_element(self.inputs, other) other_expr = "x_%d" % other_idx - elif isinstance(other, NUMERIC_TYPES): + elif isinstance(other, Number): self_expr = self._expr other_expr = str(other) new_inputs = self.inputs diff --git a/zipline/modelling/factor/factor.py b/zipline/modelling/factor/factor.py index b8eb0ca1..37861c4f 100644 --- a/zipline/modelling/factor/factor.py +++ b/zipline/modelling/factor/factor.py @@ -2,6 +2,8 @@ factor.py """ from operator import attrgetter +from numbers import Number + from numpy import ( apply_along_axis, float64, @@ -27,7 +29,6 @@ from zipline.modelling.expression import ( is_comparison, MATH_BINOPS, method_name_for_op, - NUMERIC_TYPES, NumericalExpression, NUMEXPR_MATH_FUNCS, UNARY_OPS, @@ -93,7 +94,7 @@ def binary_operator(op): "x_0 {op} x_1".format(op=op), (self, other), ) - elif isinstance(other, NUMERIC_TYPES): + elif isinstance(other, Number): return return_type( "x_0 {op} ({constant})".format(op=op, constant=other), binds=(self,), @@ -129,7 +130,7 @@ def reflected_binary_operator(op): # Only have to handle the numeric case because in all other valid cases # the corresponding left-binding method will be called. - elif isinstance(other, NUMERIC_TYPES): + elif isinstance(other, Number): return NumExprFactor( "{constant} {op} x_0".format(op=op, constant=other), binds=(self,),