From 8aacac1cb662f5ca57b23aacc13387fa65c71e60 Mon Sep 17 00:00:00 2001 From: Scott Sanderson Date: Tue, 22 Nov 2016 12:33:58 -0500 Subject: [PATCH] PERF: Use searchsorted instead of get_loc. On pandas < 18, `get_loc` triggers allocation of a large hash table, so we don't want to call get_loc on minutely `DatetimeIndex`es. --- zipline/data/history_loader.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zipline/data/history_loader.py b/zipline/data/history_loader.py index ccea65ec..df0b2789 100644 --- a/zipline/data/history_loader.py +++ b/zipline/data/history_loader.py @@ -380,7 +380,7 @@ class HistoryLoader(with_metaclass(ABCMeta)): assets = self._asset_finder.retrieve_all(assets) try: - end_ix = self._calendar.get_loc(end) + end_ix = self._calendar.searchsorted(end) except KeyError: raise KeyError("{0} not in calendar [{1}...{2}]".format( end, self._calendar[0], self._calendar[-1])) @@ -405,7 +405,7 @@ class HistoryLoader(with_metaclass(ABCMeta)): offset = 0 try: - start_ix = self._calendar.get_loc(start) + start_ix = self._calendar.searchsorted(start) except KeyError: raise KeyError("{0} not in calendar [{1}...{2}]".format( start, self._calendar[0], self._calendar[-1])) @@ -537,7 +537,7 @@ class HistoryLoader(with_metaclass(ABCMeta)): dts, field, is_perspective_after) - end_ix = self._calendar.get_loc(dts[-1]) + end_ix = self._calendar.searchsorted(dts[-1]) return concatenate( [window.get(end_ix) for window in block],