mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-07 10:54:36 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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,),
|
||||
|
||||
Reference in New Issue
Block a user