mirror of
https://github.com/wassname/catalyst.git
synced 2026-09-09 11:19:23 +08:00
MAINT: Use six for Python 3 compatible names and behavior.
Use the six module to import functions and types that are consistent between Python 2 and 3, so that one code base can support both versions. - Use integer types instead of int and long. - Use string_types instead of basestring. - Account for iteritems, itervalues, iterkeys. - Use six.moves for filter and zip, reduce - Use compatible bytes for md5 hasher. - xrange and range
This commit is contained in:
@@ -28,6 +28,8 @@ import numpy as np
|
||||
|
||||
from nose.tools import timed
|
||||
|
||||
from six.moves import range
|
||||
|
||||
import zipline.protocol
|
||||
from zipline.protocol import Event, DATASOURCE_TYPE
|
||||
|
||||
@@ -314,7 +316,7 @@ class FinanceTestCase(TestCase):
|
||||
alternator = 1
|
||||
|
||||
order_date = start_date
|
||||
for i in xrange(order_count):
|
||||
for i in range(order_count):
|
||||
|
||||
blotter.set_date(order_date)
|
||||
blotter.order(sid, order_amount * alternator ** i, None, None)
|
||||
@@ -334,7 +336,7 @@ class FinanceTestCase(TestCase):
|
||||
order_list = oo[sid]
|
||||
self.assertEqual(order_count, len(order_list))
|
||||
|
||||
for i in xrange(order_count):
|
||||
for i in range(order_count):
|
||||
order = order_list[i]
|
||||
self.assertEqual(order.sid, sid)
|
||||
self.assertEqual(order.amount, order_amount * alternator ** i)
|
||||
@@ -372,7 +374,7 @@ class FinanceTestCase(TestCase):
|
||||
self.assertEqual(len(transactions), len(order_list))
|
||||
|
||||
total_volume = 0
|
||||
for i in xrange(len(transactions)):
|
||||
for i in range(len(transactions)):
|
||||
txn = transactions[i]
|
||||
total_volume += txn.amount
|
||||
if complete_fill:
|
||||
|
||||
@@ -24,6 +24,8 @@ import datetime
|
||||
import pytz
|
||||
import itertools
|
||||
|
||||
from six.moves import range
|
||||
|
||||
import zipline.utils.factory as factory
|
||||
import zipline.finance.performance as perf
|
||||
from zipline.finance.slippage import Transaction, create_transaction
|
||||
@@ -431,7 +433,7 @@ class TestDividendPerformance(unittest.TestCase):
|
||||
|
||||
pay_date = self.sim_params.first_open
|
||||
# find pay date that is much later.
|
||||
for i in xrange(30):
|
||||
for i in range(30):
|
||||
pay_date = factory.get_next_trading_dt(pay_date, oneday)
|
||||
dividend = factory.create_dividend(
|
||||
1,
|
||||
|
||||
@@ -16,6 +16,8 @@ import pandas as pd
|
||||
import pytz
|
||||
from itertools import cycle
|
||||
|
||||
from six import integer_types
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
import zipline.utils.factory as factory
|
||||
@@ -71,5 +73,5 @@ class TestDataFrameSource(TestCase):
|
||||
for event in source:
|
||||
for check_field in check_fields:
|
||||
self.assertIn(check_field, event)
|
||||
self.assertTrue(isinstance(event['volume'], (int, long)))
|
||||
self.assertTrue(isinstance(event['volume'], (integer_types)))
|
||||
self.assertEqual(stocks_iter.next(), event['sid'])
|
||||
|
||||
@@ -20,6 +20,8 @@ import pandas as pd
|
||||
from datetime import timedelta, datetime
|
||||
from unittest import TestCase
|
||||
|
||||
from six.moves import range
|
||||
|
||||
from zipline.utils.test_utils import setup_logger
|
||||
|
||||
from zipline.protocol import Event
|
||||
@@ -64,7 +66,7 @@ class TestEventWindow(TestCase):
|
||||
|
||||
self.monday = datetime(2012, 7, 9, 16, tzinfo=pytz.utc)
|
||||
self.eleven_normal_days = [self.monday + i * timedelta(days=1)
|
||||
for i in xrange(11)]
|
||||
for i in range(11)]
|
||||
|
||||
# Modify the end of the period slightly to exercise the
|
||||
# incomplete day logic.
|
||||
@@ -75,7 +77,7 @@ class TestEventWindow(TestCase):
|
||||
# Second set of dates to test holiday handling.
|
||||
self.jul4_monday = datetime(2012, 7, 2, 16, tzinfo=pytz.utc)
|
||||
self.week_of_jul4 = [self.jul4_monday + i * timedelta(days=1)
|
||||
for i in xrange(5)]
|
||||
for i in range(5)]
|
||||
|
||||
def test_market_aware_window_normal_week(self):
|
||||
window = NoopEventWindow(
|
||||
|
||||
Reference in New Issue
Block a user