From aa585b1cf8d0ef4e40fc99b4f7a26a92a8ba3f18 Mon Sep 17 00:00:00 2001 From: Jonathan Kamens Date: Thu, 5 Mar 2015 14:25:04 -0500 Subject: [PATCH] BUG: Fix Python 3 support for Cythonized Security object Python 3 for some reason doesn't like usage of the cmp() built-in, so instead of using cmp(), just subtract the two ints being compared. In addition to making this work with Python 3, it should also be more performant since it no longer requires calling the cmp() method. --- zipline/assets/_securities.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/zipline/assets/_securities.pyx b/zipline/assets/_securities.pyx index 3d7cf539..8f0cd400 100644 --- a/zipline/assets/_securities.pyx +++ b/zipline/assets/_securities.pyx @@ -99,7 +99,7 @@ cdef class Security: retvals = [True, True, False, True, False, False] return retvals[op] - compared = cmp(self.sid, other_as_int) + compared = self.sid - other_as_int # Handle == and != first because they're significantly more common # operations. @@ -111,16 +111,16 @@ cdef class Security: return compared != 0 elif op == 0: # < - return compared == -1 + return compared < 0 elif op == 1: # <= - return compared == -1 or compared == 0 + return compared <= 0 elif op == 4: # > - return compared == 1 + return compared > 0 elif op == 5: # >= - return compared == 1 or compared == 0 + return compared >= 0 def __str__(self): if self.symbol: