{"action":"created","comment":{"url":"https://api.github.com/repos/quantopian/zipline/pulls/comments/51954486","id":51954486,"diff_hunk":"@@ -391,3 +395,85 @@ def _update_buffer(self, frame):\n             self.buffer.loc[non_nan_items, :, non_nan_cols])\n \n         self.buffer = new_buffer\n+\n+\n+class SortedDict(MutableMapping):\n+    \"\"\"A mapping of key-value pairs sorted by key according to the sort_key\n+    function provided to the mapping.  Ties from the sort_key are broken by\n+    comparing the original keys.  `iter` traverses the keys in sort order.\n+\n+    Parameters\n+    ----------\n+    mapping : mapping, optional\n+    **kwargs\n+        The initial mapping. This will double as the starting mapping so\n+        the values must also be hashable.\n+\n+    >>> d = SortedDict(abs)\n+    >>> d[-1] = 'negative one'\n+    >>> d[0] = 'zero'\n+    >>> d[2] = 'two'\n+    >>> d  # doctest: +NORMALIZE_WHITESPACE\n+    SortedDict[<built-in function abs>]([(0, 'zero'),\n+                                         (-1, 'negative one'),\n+                                         (2, 'two')])\n+    >>> d[1] = 'one'  # Mutating the mapping maintains the sort order.\n+    >>> d  # doctest: +NORMALIZE_WHITESPACE\n+    SortedDict[<built-in function abs>]([(0, 'zero'),\n+                                         (-1, 'negative one'),\n+                                         (1, 'one'),\n+                                         (2, 'two')])\n+    >>> del d[0]\n+    >>> d  # doctest: +NORMALIZE_WHITESPACE\n+    SortedDict[<built-in function abs>]([(-1, 'negative one'),\n+                                         (1, 'one'),\n+                                         (2, 'two')])\n+    >>> del d[2]\n+    >>> d  # doctest: +NORMALIZE_WHITESPACE\n+    SortedDict[<built-in function abs>]([(-1, 'negative one'),\n+                                         (1, 'one')])\n+    \"\"\"\n+    def __init__(self, sort_key, mapping=None, **kwargs):\n+        self._map = {}\n+        self._sorted_key_names = []\n+        self._sort_key = sort_key\n+\n+        self.update(merge(mapping or {}, kwargs))\n+\n+    def __getitem__(self, name):\n+        return self._map[name]\n+\n+    def __setitem__(self, name, value, _bisect_right=bisect.bisect_right):\n+        self._map[name] = value\n+        if len(self._map) > len(self._sorted_key_names):\n+            key = self._sort_key(name)\n+            pair = (key, name)\n+            idx = _bisect_right(self._sorted_key_names, pair)\n+            self._sorted_key_names.insert(idx, pair)\n+\n+    def __delitem__(self, name, _bisect_right=bisect.bisect_right):\n+        del self._map[name]\n+        idx = _bisect_right(self._sorted_key_names,\n+                            (self._sort_key(name), name))\n+        del self._sorted_key_names[idx - 1]\n+\n+    def __iter__(self):\n+        for key, name in self._sorted_key_names:\n+            yield name\n+\n+    def __len__(self):\n+        return len(self._map)\n+\n+    def __repr__(self, _repr_running={}):\n+        # Based on OrderedDict/defaultdict\n+        call_key = id(self), get_ident()\n+        if call_key in _repr_running:\n+            return '...'\n+        _repr_running[call_key] = 1\n+        try:\n+            if not self:\n+                return '%s[%r]()' % (self.__class__.__name__, self._sort_key)\n+            return '%s[%r](%r)' % (self.__class__.__name__, self._sort_key,","path":"zipline/utils/data.py","position":102,"original_position":99,"commit_id":"81627b80e44e32e83e91f550214be8274ae034e0","original_commit_id":"e771b9b878dfe65981cb777196b675bc2284e0a4","user":{"login":"richafrank","id":2123660,"avatar_url":"https://avatars.githubusercontent.com/u/2123660?v=3","gravatar_id":"","url":"https://api.github.com/users/richafrank","html_url":"https://github.com/richafrank","followers_url":"https://api.github.com/users/richafrank/followers","following_url":"https://api.github.com/users/richafrank/following{/other_user}","gists_url":"https://api.github.com/users/richafrank/gists{/gist_id}","starred_url":"https://api.github.com/users/richafrank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richafrank/subscriptions","organizations_url":"https://api.github.com/users/richafrank/orgs","repos_url":"https://api.github.com/users/richafrank/repos","events_url":"https://api.github.com/users/richafrank/events{/privacy}","received_events_url":"https://api.github.com/users/richafrank/received_events","type":"User","site_admin":false},"body":"Good call.","created_at":"2016-02-04T23:19:33Z","updated_at":"2016-02-04T23:19:33Z","html_url":"https://github.com/quantopian/zipline/pull/983#discussion_r51954486","pull_request_url":"https://api.github.com/repos/quantopian/zipline/pulls/983","_links":{"self":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/comments/51954486"},"html":{"href":"https://github.com/quantopian/zipline/pull/983#discussion_r51954486"},"pull_request":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/983"}}},"pull_request":{"url":"https://api.github.com/repos/quantopian/zipline/pulls/983","id":58364133,"html_url":"https://github.com/quantopian/zipline/pull/983","diff_url":"https://github.com/quantopian/zipline/pull/983.diff","patch_url":"https://github.com/quantopian/zipline/pull/983.patch","issue_url":"https://api.github.com/repos/quantopian/zipline/issues/983","number":983,"state":"open","locked":false,"title":"Expiration perf","user":{"login":"richafrank","id":2123660,"avatar_url":"https://avatars.githubusercontent.com/u/2123660?v=3","gravatar_id":"","url":"https://api.github.com/users/richafrank","html_url":"https://github.com/richafrank","followers_url":"https://api.github.com/users/richafrank/followers","following_url":"https://api.github.com/users/richafrank/following{/other_user}","gists_url":"https://api.github.com/users/richafrank/gists{/gist_id}","starred_url":"https://api.github.com/users/richafrank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richafrank/subscriptions","organizations_url":"https://api.github.com/users/richafrank/orgs","repos_url":"https://api.github.com/users/richafrank/repos","events_url":"https://api.github.com/users/richafrank/events{/privacy}","received_events_url":"https://api.github.com/users/richafrank/received_events","type":"User","site_admin":false},"body":"Look up expired futures from in-memory Futures instead of queries to the db.","created_at":"2016-02-04T23:05:49Z","updated_at":"2016-02-04T23:19:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"228e594013d1c3cf97c1d1b4749a6309db4e5213","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/quantopian/zipline/pulls/983/commits","review_comments_url":"https://api.github.com/repos/quantopian/zipline/pulls/983/comments","review_comment_url":"https://api.github.com/repos/quantopian/zipline/pulls/comments{/number}","comments_url":"https://api.github.com/repos/quantopian/zipline/issues/983/comments","statuses_url":"https://api.github.com/repos/quantopian/zipline/statuses/81627b80e44e32e83e91f550214be8274ae034e0","head":{"label":"quantopian:expiration_perf","ref":"expiration_perf","sha":"81627b80e44e32e83e91f550214be8274ae034e0","user":{"login":"quantopian","id":1393215,"avatar_url":"https://avatars.githubusercontent.com/u/1393215?v=3","gravatar_id":"","url":"https://api.github.com/users/quantopian","html_url":"https://github.com/quantopian","followers_url":"https://api.github.com/users/quantopian/followers","following_url":"https://api.github.com/users/quantopian/following{/other_user}","gists_url":"https://api.github.com/users/quantopian/gists{/gist_id}","starred_url":"https://api.github.com/users/quantopian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quantopian/subscriptions","organizations_url":"https://api.github.com/users/quantopian/orgs","repos_url":"https://api.github.com/users/quantopian/repos","events_url":"https://api.github.com/users/quantopian/events{/privacy}","received_events_url":"https://api.github.com/users/quantopian/received_events","type":"Organization","site_admin":false},"repo":{"id":6297520,"name":"zipline","full_name":"quantopian/zipline","owner":{"login":"quantopian","id":1393215,"avatar_url":"https://avatars.githubusercontent.com/u/1393215?v=3","gravatar_id":"","url":"https://api.github.com/users/quantopian","html_url":"https://github.com/quantopian","followers_url":"https://api.github.com/users/quantopian/followers","following_url":"https://api.github.com/users/quantopian/following{/other_user}","gists_url":"https://api.github.com/users/quantopian/gists{/gist_id}","starred_url":"https://api.github.com/users/quantopian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quantopian/subscriptions","organizations_url":"https://api.github.com/users/quantopian/orgs","repos_url":"https://api.github.com/users/quantopian/repos","events_url":"https://api.github.com/users/quantopian/events{/privacy}","received_events_url":"https://api.github.com/users/quantopian/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/quantopian/zipline","description":"Zipline, a Pythonic Algorithmic Trading Library","fork":false,"url":"https://api.github.com/repos/quantopian/zipline","forks_url":"https://api.github.com/repos/quantopian/zipline/forks","keys_url":"https://api.github.com/repos/quantopian/zipline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/quantopian/zipline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/quantopian/zipline/teams","hooks_url":"https://api.github.com/repos/quantopian/zipline/hooks","issue_events_url":"https://api.github.com/repos/quantopian/zipline/issues/events{/number}","events_url":"https://api.github.com/repos/quantopian/zipline/events","assignees_url":"https://api.github.com/repos/quantopian/zipline/assignees{/user}","branches_url":"https://api.github.com/repos/quantopian/zipline/branches{/branch}","tags_url":"https://api.github.com/repos/quantopian/zipline/tags","blobs_url":"https://api.github.com/repos/quantopian/zipline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/quantopian/zipline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/quantopian/zipline/git/refs{/sha}","trees_url":"https://api.github.com/repos/quantopian/zipline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/quantopian/zipline/statuses/{sha}","languages_url":"https://api.github.com/repos/quantopian/zipline/languages","stargazers_url":"https://api.github.com/repos/quantopian/zipline/stargazers","contributors_url":"https://api.github.com/repos/quantopian/zipline/contributors","subscribers_url":"https://api.github.com/repos/quantopian/zipline/subscribers","subscription_url":"https://api.github.com/repos/quantopian/zipline/subscription","commits_url":"https://api.github.com/repos/quantopian/zipline/commits{/sha}","git_commits_url":"https://api.github.com/repos/quantopian/zipline/git/commits{/sha}","comments_url":"https://api.github.com/repos/quantopian/zipline/comments{/number}","issue_comment_url":"https://api.github.com/repos/quantopian/zipline/issues/comments{/number}","contents_url":"https://api.github.com/repos/quantopian/zipline/contents/{+path}","compare_url":"https://api.github.com/repos/quantopian/zipline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/quantopian/zipline/merges","archive_url":"https://api.github.com/repos/quantopian/zipline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/quantopian/zipline/downloads","issues_url":"https://api.github.com/repos/quantopian/zipline/issues{/number}","pulls_url":"https://api.github.com/repos/quantopian/zipline/pulls{/number}","milestones_url":"https://api.github.com/repos/quantopian/zipline/milestones{/number}","notifications_url":"https://api.github.com/repos/quantopian/zipline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/quantopian/zipline/labels{/name}","releases_url":"https://api.github.com/repos/quantopian/zipline/releases{/id}","deployments_url":"https://api.github.com/repos/quantopian/zipline/deployments","created_at":"2012-10-19T15:50:29Z","updated_at":"2016-02-04T21:50:19Z","pushed_at":"2016-02-04T23:17:41Z","git_url":"git://github.com/quantopian/zipline.git","ssh_url":"git@github.com:quantopian/zipline.git","clone_url":"https://github.com/quantopian/zipline.git","svn_url":"https://github.com/quantopian/zipline","homepage":"","size":14998,"stargazers_count":2868,"watchers_count":2868,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":834,"mirror_url":null,"open_issues_count":157,"forks":834,"open_issues":157,"watchers":2868,"default_branch":"master"}},"base":{"label":"quantopian:master","ref":"master","sha":"f5b74bf7c50c8a7b247db553f85803e69c6733c7","user":{"login":"quantopian","id":1393215,"avatar_url":"https://avatars.githubusercontent.com/u/1393215?v=3","gravatar_id":"","url":"https://api.github.com/users/quantopian","html_url":"https://github.com/quantopian","followers_url":"https://api.github.com/users/quantopian/followers","following_url":"https://api.github.com/users/quantopian/following{/other_user}","gists_url":"https://api.github.com/users/quantopian/gists{/gist_id}","starred_url":"https://api.github.com/users/quantopian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quantopian/subscriptions","organizations_url":"https://api.github.com/users/quantopian/orgs","repos_url":"https://api.github.com/users/quantopian/repos","events_url":"https://api.github.com/users/quantopian/events{/privacy}","received_events_url":"https://api.github.com/users/quantopian/received_events","type":"Organization","site_admin":false},"repo":{"id":6297520,"name":"zipline","full_name":"quantopian/zipline","owner":{"login":"quantopian","id":1393215,"avatar_url":"https://avatars.githubusercontent.com/u/1393215?v=3","gravatar_id":"","url":"https://api.github.com/users/quantopian","html_url":"https://github.com/quantopian","followers_url":"https://api.github.com/users/quantopian/followers","following_url":"https://api.github.com/users/quantopian/following{/other_user}","gists_url":"https://api.github.com/users/quantopian/gists{/gist_id}","starred_url":"https://api.github.com/users/quantopian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quantopian/subscriptions","organizations_url":"https://api.github.com/users/quantopian/orgs","repos_url":"https://api.github.com/users/quantopian/repos","events_url":"https://api.github.com/users/quantopian/events{/privacy}","received_events_url":"https://api.github.com/users/quantopian/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/quantopian/zipline","description":"Zipline, a Pythonic Algorithmic Trading Library","fork":false,"url":"https://api.github.com/repos/quantopian/zipline","forks_url":"https://api.github.com/repos/quantopian/zipline/forks","keys_url":"https://api.github.com/repos/quantopian/zipline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/quantopian/zipline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/quantopian/zipline/teams","hooks_url":"https://api.github.com/repos/quantopian/zipline/hooks","issue_events_url":"https://api.github.com/repos/quantopian/zipline/issues/events{/number}","events_url":"https://api.github.com/repos/quantopian/zipline/events","assignees_url":"https://api.github.com/repos/quantopian/zipline/assignees{/user}","branches_url":"https://api.github.com/repos/quantopian/zipline/branches{/branch}","tags_url":"https://api.github.com/repos/quantopian/zipline/tags","blobs_url":"https://api.github.com/repos/quantopian/zipline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/quantopian/zipline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/quantopian/zipline/git/refs{/sha}","trees_url":"https://api.github.com/repos/quantopian/zipline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/quantopian/zipline/statuses/{sha}","languages_url":"https://api.github.com/repos/quantopian/zipline/languages","stargazers_url":"https://api.github.com/repos/quantopian/zipline/stargazers","contributors_url":"https://api.github.com/repos/quantopian/zipline/contributors","subscribers_url":"https://api.github.com/repos/quantopian/zipline/subscribers","subscription_url":"https://api.github.com/repos/quantopian/zipline/subscription","commits_url":"https://api.github.com/repos/quantopian/zipline/commits{/sha}","git_commits_url":"https://api.github.com/repos/quantopian/zipline/git/commits{/sha}","comments_url":"https://api.github.com/repos/quantopian/zipline/comments{/number}","issue_comment_url":"https://api.github.com/repos/quantopian/zipline/issues/comments{/number}","contents_url":"https://api.github.com/repos/quantopian/zipline/contents/{+path}","compare_url":"https://api.github.com/repos/quantopian/zipline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/quantopian/zipline/merges","archive_url":"https://api.github.com/repos/quantopian/zipline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/quantopian/zipline/downloads","issues_url":"https://api.github.com/repos/quantopian/zipline/issues{/number}","pulls_url":"https://api.github.com/repos/quantopian/zipline/pulls{/number}","milestones_url":"https://api.github.com/repos/quantopian/zipline/milestones{/number}","notifications_url":"https://api.github.com/repos/quantopian/zipline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/quantopian/zipline/labels{/name}","releases_url":"https://api.github.com/repos/quantopian/zipline/releases{/id}","deployments_url":"https://api.github.com/repos/quantopian/zipline/deployments","created_at":"2012-10-19T15:50:29Z","updated_at":"2016-02-04T21:50:19Z","pushed_at":"2016-02-04T23:17:41Z","git_url":"git://github.com/quantopian/zipline.git","ssh_url":"git@github.com:quantopian/zipline.git","clone_url":"https://github.com/quantopian/zipline.git","svn_url":"https://github.com/quantopian/zipline","homepage":"","size":14998,"stargazers_count":2868,"watchers_count":2868,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":834,"mirror_url":null,"open_issues_count":157,"forks":834,"open_issues":157,"watchers":2868,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/983"},"html":{"href":"https://github.com/quantopian/zipline/pull/983"},"issue":{"href":"https://api.github.com/repos/quantopian/zipline/issues/983"},"comments":{"href":"https://api.github.com/repos/quantopian/zipline/issues/983/comments"},"review_comments":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/983/comments"},"review_comment":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/983/commits"},"statuses":{"href":"https://api.github.com/repos/quantopian/zipline/statuses/81627b80e44e32e83e91f550214be8274ae034e0"}}}}