From 845712e5ebcc78190b2d40af78c838895fec591c Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Mon, 30 Jun 2014 17:49:27 +0200 Subject: [PATCH] MAINT: Factor out column conversion in HistoryContainer. We can't be sure that security identifiers can be converted to int. In fact, most of the times they are strings. This adds an identity function that can be overwritten if such a conversion is necessary (as on Quantopian). --- zipline/history/history_container.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/zipline/history/history_container.py b/zipline/history/history_container.py index 51b38562..7c8eece4 100644 --- a/zipline/history/history_container.py +++ b/zipline/history/history_container.py @@ -246,6 +246,13 @@ class HistoryContainer(object): ) return rp + def convert_columns(self, values): + """ + If columns have a specific type you want to enforce, overwrite this + method and return the transformed values. + """ + return values + def create_return_frames(self, algo_dt): """ Populates the return frame cache. @@ -257,7 +264,8 @@ class HistoryContainer(object): index = pd.to_datetime(index_at_dt(history_spec, algo_dt)) frame = pd.DataFrame( index=index, - columns=map(int, self.buffer_panel.minor_axis.values), + columns=self.convert_columns( + self.buffer_panel.minor_axis.values), dtype=np.float64) self.return_frames[spec_key] = frame