From 2c3d9a84db9efbb577e75bc1a236b7a7555c08bd Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 21 Nov 2012 17:54:57 -0500 Subject: [PATCH] Fills in missing slots in transform data panels. Forward fills data, so that when using multiple stocks, we don't have cases where one stock has data and the other doesn't. --- zipline/transforms/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zipline/transforms/utils.py b/zipline/transforms/utils.py index 0e1b6868..97e5a25d 100644 --- a/zipline/transforms/utils.py +++ b/zipline/transforms/utils.py @@ -454,6 +454,16 @@ class BatchTransform(EventWindow): fields[field_name] = pd.DataFrame.from_dict(values_per_sid) data = pd.Panel.from_dict(fields, orient='items') + + # Fills in gaps of missing data during transform of multiple + # stocks. + # e.g. we may be missing minute data because of illiquidity + # of one stock + data = data.fillna(method='ffill') + # Drop any empty rows after the fill. + # This will drop a leading row of N/A + data = data.dropna() + return data def handle_remove(self, event):