BUG: Use numbers.Number to check numbers.

Fixes a bug on Python3 due to the fact that numpy.int64 isn't an
instance of int on Py3.
This commit is contained in:
Scott Sanderson
2015-09-30 16:17:25 -04:00
parent 0a39225c1e
commit 1d1092152c
2 changed files with 6 additions and 6 deletions
+2 -3
View File
@@ -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
+4 -3
View File
@@ -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,),