From e9376453f45dd1ffdcc1015e5ae29b54a4f51e6c Mon Sep 17 00:00:00 2001 From: llllllllll Date: Mon, 9 Nov 2015 16:50:16 -0500 Subject: [PATCH] BUG: the simple transform caching caused the length of the siddata object to change which would mark it as not-empty --- zipline/protocol.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/zipline/protocol.py b/zipline/protocol.py index 7353a76b..db6c1466 100644 --- a/zipline/protocol.py +++ b/zipline/protocol.py @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - from copy import copy from six import iteritems, iterkeys @@ -377,7 +376,7 @@ class SIDData(object): else: return buffer_[self._sid][-bars:] - def _get_bars(self, days): + def _cache_daily_minutely(self, days, fn): """ Gets the number of bars needed for the current number of days. @@ -439,8 +438,20 @@ class SIDData(object): self._get_bars = minute_get_bars self._get_max_bars = minute_get_max_bars + # NOTE: This silently adds these two entries to the `__dict__` + # without affecting the `__len__` of the object. This is important + # because we use the `len` of the `SIDData` object to see if we have + # data for this asset. + self._initial_len += 2 + # Not actually recursive because we have already cached the new method. - return self._get_bars(days) + return getattr(self, fn)(days) + + def _get_bars(self, bars): + return self._cache_daily_minutely(bars, fn='_get_bars') + + def _get_max_bars(self, bars): + return self._cache_daily_minutely(bars, fn='_get_max_bars') def mavg(self, days): bars = self._get_bars(days)