From 08a0d1b604c427b6d219e3a7bcf9efb619b0958c Mon Sep 17 00:00:00 2001 From: fawce Date: Thu, 5 Feb 2015 13:04:05 -0500 Subject: [PATCH] python 3.3 compatible iterators --- tests/test_security_list.py | 16 +++++++++------- zipline/utils/security_list.py | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/test_security_list.py b/tests/test_security_list.py index 2a18216f..2b65fc9e 100644 --- a/tests/test_security_list.py +++ b/tests/test_security_list.py @@ -68,7 +68,7 @@ class SecurityListTestCase(TestCase): def test_iterate_over_rl(self): sim_params = factory.create_simulation_parameters( - start=LEVERAGED_ETFS.keys()[0], num_days=4) + start=list(LEVERAGED_ETFS.keys())[0], num_days=4) trade_history = factory.create_trade_history( 'BZQ', @@ -87,7 +87,7 @@ class SecurityListTestCase(TestCase): # set the knowledge date to the first day of the # leveraged etf knowledge date. def get_datetime(): - return LEVERAGED_ETFS.keys()[0] + return list(LEVERAGED_ETFS.keys())[0] rl = SecurityListSet(get_datetime) # assert that a sample from the leveraged list are in restricted @@ -127,7 +127,7 @@ class SecurityListTestCase(TestCase): def test_algo_without_rl_violation_via_check(self): sim_params = factory.create_simulation_parameters( - start=LEVERAGED_ETFS.keys()[0], num_days=4) + start=list(LEVERAGED_ETFS.keys())[0], num_days=4) trade_history = factory.create_trade_history( 'BZQ', @@ -143,7 +143,7 @@ class SecurityListTestCase(TestCase): def test_algo_without_rl_violation(self): sim_params = factory.create_simulation_parameters( - start=LEVERAGED_ETFS.keys()[0], num_days=4) + start=list(LEVERAGED_ETFS.keys())[0], num_days=4) trade_history = factory.create_trade_history( 'AAPL', @@ -158,7 +158,7 @@ class SecurityListTestCase(TestCase): def test_algo_with_rl_violation(self): sim_params = factory.create_simulation_parameters( - start=LEVERAGED_ETFS.keys()[0], num_days=4) + start=list(LEVERAGED_ETFS.keys())[0], num_days=4) trade_history = factory.create_trade_history( 'BZQ', @@ -199,7 +199,8 @@ class SecurityListTestCase(TestCase): def test_algo_with_rl_violation_after_knowledge_date(self): sim_params = factory.create_simulation_parameters( - start=LEVERAGED_ETFS.keys()[0] + timedelta(days=7), num_days=5) + start=list( + LEVERAGED_ETFS.keys())[0] + timedelta(days=7), num_days=5) trade_history = factory.create_trade_history( 'BZQ', @@ -222,7 +223,8 @@ class SecurityListTestCase(TestCase): set is still disallowed. """ sim_params = factory.create_simulation_parameters( - start=LEVERAGED_ETFS.keys()[0] + timedelta(days=7), num_days=4) + start=list( + LEVERAGED_ETFS.keys())[0] + timedelta(days=7), num_days=4) try: add_security_data(['AAPL'], []) diff --git a/zipline/utils/security_list.py b/zipline/utils/security_list.py index 725d8321..6fb046e7 100644 --- a/zipline/utils/security_list.py +++ b/zipline/utils/security_list.py @@ -77,7 +77,7 @@ class SecurityList(object): self._current_set = self._cache[kd] continue - for effective_date, changes in self.data[kd].iteritems(): + for effective_date, changes in iter(self.data[kd].items()): self.update_current( effective_date, changes['add'],