mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-06 02:45:53 +08:00
BUG: Enable comparison of an Asset to an int64 on 32-bit python
We use a number of mappings keyed by int64, which otherwise raised KeyErrors for Assets.
This commit is contained in:
+10
-2
@@ -29,7 +29,7 @@ from pandas.tseries.tools import normalize_date
|
||||
from pandas.util.testing import assert_frame_equal
|
||||
|
||||
from nose_parameterized import parameterized
|
||||
from numpy import full
|
||||
from numpy import full, int32, int64
|
||||
import sqlalchemy as sa
|
||||
|
||||
from zipline.assets import (
|
||||
@@ -39,7 +39,7 @@ from zipline.assets import (
|
||||
AssetFinder,
|
||||
AssetFinderCachedEquities,
|
||||
)
|
||||
from six import itervalues
|
||||
from six import itervalues, integer_types
|
||||
from toolz import valmap
|
||||
|
||||
from zipline.assets.futures import (
|
||||
@@ -212,6 +212,14 @@ class AssetTestCase(TestCase):
|
||||
self.assertEqual(s_23, s_23)
|
||||
self.assertEqual(s_23, 23)
|
||||
self.assertEqual(23, s_23)
|
||||
self.assertEqual(int32(23), s_23)
|
||||
self.assertEqual(int64(23), s_23)
|
||||
self.assertEqual(s_23, int32(23))
|
||||
self.assertEqual(s_23, int64(23))
|
||||
# Check all int types (includes long on py2):
|
||||
for int_type in integer_types:
|
||||
self.assertEqual(int_type(23), s_23)
|
||||
self.assertEqual(s_23, int_type(23))
|
||||
|
||||
self.assertNotEqual(s_23, s_24)
|
||||
self.assertNotEqual(s_23, 24)
|
||||
|
||||
@@ -19,6 +19,8 @@ Cythonized Asset object.
|
||||
"""
|
||||
cimport cython
|
||||
|
||||
from numbers import Integral
|
||||
|
||||
import numpy as np
|
||||
import warnings
|
||||
cimport numpy as np
|
||||
@@ -86,14 +88,20 @@ cdef class Asset:
|
||||
if isinstance(x, Asset):
|
||||
x_as_int = x.sid
|
||||
elif isinstance(x, int):
|
||||
# ints are Integral, but much faster to special case
|
||||
x_as_int = x
|
||||
elif isinstance(x, (long, np.int64, np.int32, Integral)):
|
||||
x_as_int = int(x)
|
||||
else:
|
||||
return NotImplemented
|
||||
|
||||
if isinstance(y, Asset):
|
||||
y_as_int = y.sid
|
||||
elif isinstance(y, int):
|
||||
# ints are Integral, but much faster to special case
|
||||
y_as_int = y
|
||||
elif isinstance(y, (long, np.int64, np.int32, Integral)):
|
||||
y_as_int = int(y)
|
||||
else:
|
||||
return NotImplemented
|
||||
|
||||
|
||||
Reference in New Issue
Block a user