From 92f1dbef0cd1e6911d95eea5a7cdd122c1c8dc51 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Fri, 19 Oct 2012 11:47:59 -0500 Subject: [PATCH] Fixes bug that .run() could not be called twice on an algorithm. Added unittest to check. --- tests/test_algorithm.py | 8 ++++++++ zipline/algorithm.py | 1 + 2 files changed, 9 insertions(+) diff --git a/tests/test_algorithm.py b/tests/test_algorithm.py index 52666921..77568abf 100644 --- a/tests/test_algorithm.py +++ b/tests/test_algorithm.py @@ -15,6 +15,7 @@ from unittest2 import TestCase from datetime import timedelta +import numpy as np from zipline.utils.test_utils import setup_logger import zipline.utils.factory as factory @@ -62,6 +63,13 @@ class TestTransformAlgorithm(TestCase): algo.run(self.df) assert isinstance(algo.sources[0], DataFrameSource) + def test_run_twice(self): + algo = TestRegisterTransformAlgorithm(sids=[0, 1]) + res1 = algo.run(self.df) + res2 = algo.run(self.df) + + np.testing.assert_array_equal(res1, res2) + def test_transform_registered(self): algo = TestRegisterTransformAlgorithm(sids=[133]) algo.run(self.source) diff --git a/zipline/algorithm.py b/zipline/algorithm.py index 7b25a982..f6efeb0b 100644 --- a/zipline/algorithm.py +++ b/zipline/algorithm.py @@ -153,6 +153,7 @@ start and end date have to be specified.""" self.sources = source # Create transforms by wrapping them into StatefulTransforms + self.transforms = [] for namestring, trans_descr in self.registered_transforms.iteritems(): sf = StatefulTransform( trans_descr['class'],