{"action":"created","comment":{"url":"https://api.github.com/repos/ContinuumIO/dask/pulls/comments/23165915","id":23165915,"diff_hunk":"@@ -194,3 +195,31 @@ def reverse_dict(d):\n             result[val].add(k)\n     return result\n \n+\n+def cull(dsk, keys):\n+    \"\"\" Return new dask with only the tasks required to calculate keys.\n+\n+    In other words, remove unnecessary tasks from dask.\n+    ``keys`` may be a single key or list of keys.\n+\n+    Exmaple\n+    -------\n+\n+    >>> d = {'x': 1, 'y': (inc, 'x'), 'out': (add, 'x', 10)}\n+    >>> cull(d, 'out')  # doctest: +SKIP\n+    {'x': 1, 'out': (add, 'x', 10)}\n+    \"\"\"\n+    if not isinstance(keys, list):","path":"dask/core.py","position":25,"original_position":25,"commit_id":"67b6d05af60b1e50646857eb890038c8e5c29592","original_commit_id":"67b6d05af60b1e50646857eb890038c8e5c29592","user":{"login":"cpcloud","id":417981,"avatar_url":"https://avatars.githubusercontent.com/u/417981?v=3","gravatar_id":"","url":"https://api.github.com/users/cpcloud","html_url":"https://github.com/cpcloud","followers_url":"https://api.github.com/users/cpcloud/followers","following_url":"https://api.github.com/users/cpcloud/following{/other_user}","gists_url":"https://api.github.com/users/cpcloud/gists{/gist_id}","starred_url":"https://api.github.com/users/cpcloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cpcloud/subscriptions","organizations_url":"https://api.github.com/users/cpcloud/orgs","repos_url":"https://api.github.com/users/cpcloud/repos","events_url":"https://api.github.com/users/cpcloud/events{/privacy}","received_events_url":"https://api.github.com/users/cpcloud/received_events","type":"User","site_admin":false},"body":"can `keys` ever be a `tuple`?","created_at":"2015-01-19T15:28:43Z","updated_at":"2015-01-19T15:28:43Z","html_url":"https://github.com/ContinuumIO/dask/pull/10#discussion_r23165915","pull_request_url":"https://api.github.com/repos/ContinuumIO/dask/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/ContinuumIO/dask/pulls/comments/23165915"},"html":{"href":"https://github.com/ContinuumIO/dask/pull/10#discussion_r23165915"},"pull_request":{"href":"https://api.github.com/repos/ContinuumIO/dask/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/ContinuumIO/dask/pulls/10","id":27613489,"html_url":"https://github.com/ContinuumIO/dask/pull/10","diff_url":"https://github.com/ContinuumIO/dask/pull/10.diff","patch_url":"https://github.com/ContinuumIO/dask/pull/10.patch","issue_url":"https://api.github.com/repos/ContinuumIO/dask/issues/10","number":10,"state":"open","locked":false,"title":"Add `cull` to remove unnecessary tasks.  See issue #2.","user":{"login":"eriknw","id":2058401,"avatar_url":"https://avatars.githubusercontent.com/u/2058401?v=3","gravatar_id":"","url":"https://api.github.com/users/eriknw","html_url":"https://github.com/eriknw","followers_url":"https://api.github.com/users/eriknw/followers","following_url":"https://api.github.com/users/eriknw/following{/other_user}","gists_url":"https://api.github.com/users/eriknw/gists{/gist_id}","starred_url":"https://api.github.com/users/eriknw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eriknw/subscriptions","organizations_url":"https://api.github.com/users/eriknw/orgs","repos_url":"https://api.github.com/users/eriknw/repos","events_url":"https://api.github.com/users/eriknw/events{/privacy}","received_events_url":"https://api.github.com/users/eriknw/received_events","type":"User","site_admin":false},"body":"For now, I just put this in `dask.core`.\r\n\r\nFor posterity, the following is a more concise solution, but is slower:\r\n```python\r\nfrom toolz import concat, keyfilter\r\n\r\ndef cull(dsk, keys):\r\n    if not isinstance(keys, list):\r\n        keys = [keys]\r\n    seen = set()\r\n    cur = set(keys)\r\n    while cur:\r\n        seen.update(cur)\r\n        cur = set(concat(get_dependencies(dsk, x) for x in cur))\r\n        cur.difference_update(seen)\r\n    return keyfilter(seen.__contains__, dsk)\r\n```","created_at":"2015-01-19T15:16:57Z","updated_at":"2015-01-19T15:28:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"14a86e9603172d27e5a2cc9b0a095ea5a3184a2b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ContinuumIO/dask/pulls/10/commits","review_comments_url":"https://api.github.com/repos/ContinuumIO/dask/pulls/10/comments","review_comment_url":"https://api.github.com/repos/ContinuumIO/dask/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ContinuumIO/dask/issues/10/comments","statuses_url":"https://api.github.com/repos/ContinuumIO/dask/statuses/67b6d05af60b1e50646857eb890038c8e5c29592","head":{"label":"eriknw:cull","ref":"cull","sha":"67b6d05af60b1e50646857eb890038c8e5c29592","user":{"login":"eriknw","id":2058401,"avatar_url":"https://avatars.githubusercontent.com/u/2058401?v=3","gravatar_id":"","url":"https://api.github.com/users/eriknw","html_url":"https://github.com/eriknw","followers_url":"https://api.github.com/users/eriknw/followers","following_url":"https://api.github.com/users/eriknw/following{/other_user}","gists_url":"https://api.github.com/users/eriknw/gists{/gist_id}","starred_url":"https://api.github.com/users/eriknw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eriknw/subscriptions","organizations_url":"https://api.github.com/users/eriknw/orgs","repos_url":"https://api.github.com/users/eriknw/repos","events_url":"https://api.github.com/users/eriknw/events{/privacy}","received_events_url":"https://api.github.com/users/eriknw/received_events","type":"User","site_admin":false},"repo":{"id":29476472,"name":"dask","full_name":"eriknw/dask","owner":{"login":"eriknw","id":2058401,"avatar_url":"https://avatars.githubusercontent.com/u/2058401?v=3","gravatar_id":"","url":"https://api.github.com/users/eriknw","html_url":"https://github.com/eriknw","followers_url":"https://api.github.com/users/eriknw/followers","following_url":"https://api.github.com/users/eriknw/following{/other_user}","gists_url":"https://api.github.com/users/eriknw/gists{/gist_id}","starred_url":"https://api.github.com/users/eriknw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eriknw/subscriptions","organizations_url":"https://api.github.com/users/eriknw/orgs","repos_url":"https://api.github.com/users/eriknw/repos","events_url":"https://api.github.com/users/eriknw/events{/privacy}","received_events_url":"https://api.github.com/users/eriknw/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eriknw/dask","description":"Minimal task scheduling abstraction","fork":true,"url":"https://api.github.com/repos/eriknw/dask","forks_url":"https://api.github.com/repos/eriknw/dask/forks","keys_url":"https://api.github.com/repos/eriknw/dask/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eriknw/dask/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eriknw/dask/teams","hooks_url":"https://api.github.com/repos/eriknw/dask/hooks","issue_events_url":"https://api.github.com/repos/eriknw/dask/issues/events{/number}","events_url":"https://api.github.com/repos/eriknw/dask/events","assignees_url":"https://api.github.com/repos/eriknw/dask/assignees{/user}","branches_url":"https://api.github.com/repos/eriknw/dask/branches{/branch}","tags_url":"https://api.github.com/repos/eriknw/dask/tags","blobs_url":"https://api.github.com/repos/eriknw/dask/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eriknw/dask/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eriknw/dask/git/refs{/sha}","trees_url":"https://api.github.com/repos/eriknw/dask/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eriknw/dask/statuses/{sha}","languages_url":"https://api.github.com/repos/eriknw/dask/languages","stargazers_url":"https://api.github.com/repos/eriknw/dask/stargazers","contributors_url":"https://api.github.com/repos/eriknw/dask/contributors","subscribers_url":"https://api.github.com/repos/eriknw/dask/subscribers","subscription_url":"https://api.github.com/repos/eriknw/dask/subscription","commits_url":"https://api.github.com/repos/eriknw/dask/commits{/sha}","git_commits_url":"https://api.github.com/repos/eriknw/dask/git/commits{/sha}","comments_url":"https://api.github.com/repos/eriknw/dask/comments{/number}","issue_comment_url":"https://api.github.com/repos/eriknw/dask/issues/comments/{number}","contents_url":"https://api.github.com/repos/eriknw/dask/contents/{+path}","compare_url":"https://api.github.com/repos/eriknw/dask/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eriknw/dask/merges","archive_url":"https://api.github.com/repos/eriknw/dask/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eriknw/dask/downloads","issues_url":"https://api.github.com/repos/eriknw/dask/issues{/number}","pulls_url":"https://api.github.com/repos/eriknw/dask/pulls{/number}","milestones_url":"https://api.github.com/repos/eriknw/dask/milestones{/number}","notifications_url":"https://api.github.com/repos/eriknw/dask/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eriknw/dask/labels{/name}","releases_url":"https://api.github.com/repos/eriknw/dask/releases{/id}","created_at":"2015-01-19T15:11:48Z","updated_at":"2015-01-19T15:11:49Z","pushed_at":"2015-01-19T15:14:10Z","git_url":"git://github.com/eriknw/dask.git","ssh_url":"git@github.com:eriknw/dask.git","clone_url":"https://github.com/eriknw/dask.git","svn_url":"https://github.com/eriknw/dask","homepage":"","size":885,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ContinuumIO:master","ref":"master","sha":"f654b47a61cbbddaf5d2f4d1a3e6e07373b86709","user":{"login":"ContinuumIO","id":1158637,"avatar_url":"https://avatars.githubusercontent.com/u/1158637?v=3","gravatar_id":"","url":"https://api.github.com/users/ContinuumIO","html_url":"https://github.com/ContinuumIO","followers_url":"https://api.github.com/users/ContinuumIO/followers","following_url":"https://api.github.com/users/ContinuumIO/following{/other_user}","gists_url":"https://api.github.com/users/ContinuumIO/gists{/gist_id}","starred_url":"https://api.github.com/users/ContinuumIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ContinuumIO/subscriptions","organizations_url":"https://api.github.com/users/ContinuumIO/orgs","repos_url":"https://api.github.com/users/ContinuumIO/repos","events_url":"https://api.github.com/users/ContinuumIO/events{/privacy}","received_events_url":"https://api.github.com/users/ContinuumIO/received_events","type":"Organization","site_admin":false},"repo":{"id":28782747,"name":"dask","full_name":"ContinuumIO/dask","owner":{"login":"ContinuumIO","id":1158637,"avatar_url":"https://avatars.githubusercontent.com/u/1158637?v=3","gravatar_id":"","url":"https://api.github.com/users/ContinuumIO","html_url":"https://github.com/ContinuumIO","followers_url":"https://api.github.com/users/ContinuumIO/followers","following_url":"https://api.github.com/users/ContinuumIO/following{/other_user}","gists_url":"https://api.github.com/users/ContinuumIO/gists{/gist_id}","starred_url":"https://api.github.com/users/ContinuumIO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ContinuumIO/subscriptions","organizations_url":"https://api.github.com/users/ContinuumIO/orgs","repos_url":"https://api.github.com/users/ContinuumIO/repos","events_url":"https://api.github.com/users/ContinuumIO/events{/privacy}","received_events_url":"https://api.github.com/users/ContinuumIO/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ContinuumIO/dask","description":"Minimal task scheduling abstraction","fork":true,"url":"https://api.github.com/repos/ContinuumIO/dask","forks_url":"https://api.github.com/repos/ContinuumIO/dask/forks","keys_url":"https://api.github.com/repos/ContinuumIO/dask/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ContinuumIO/dask/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ContinuumIO/dask/teams","hooks_url":"https://api.github.com/repos/ContinuumIO/dask/hooks","issue_events_url":"https://api.github.com/repos/ContinuumIO/dask/issues/events{/number}","events_url":"https://api.github.com/repos/ContinuumIO/dask/events","assignees_url":"https://api.github.com/repos/ContinuumIO/dask/assignees{/user}","branches_url":"https://api.github.com/repos/ContinuumIO/dask/branches{/branch}","tags_url":"https://api.github.com/repos/ContinuumIO/dask/tags","blobs_url":"https://api.github.com/repos/ContinuumIO/dask/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ContinuumIO/dask/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ContinuumIO/dask/git/refs{/sha}","trees_url":"https://api.github.com/repos/ContinuumIO/dask/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ContinuumIO/dask/statuses/{sha}","languages_url":"https://api.github.com/repos/ContinuumIO/dask/languages","stargazers_url":"https://api.github.com/repos/ContinuumIO/dask/stargazers","contributors_url":"https://api.github.com/repos/ContinuumIO/dask/contributors","subscribers_url":"https://api.github.com/repos/ContinuumIO/dask/subscribers","subscription_url":"https://api.github.com/repos/ContinuumIO/dask/subscription","commits_url":"https://api.github.com/repos/ContinuumIO/dask/commits{/sha}","git_commits_url":"https://api.github.com/repos/ContinuumIO/dask/git/commits{/sha}","comments_url":"https://api.github.com/repos/ContinuumIO/dask/comments{/number}","issue_comment_url":"https://api.github.com/repos/ContinuumIO/dask/issues/comments/{number}","contents_url":"https://api.github.com/repos/ContinuumIO/dask/contents/{+path}","compare_url":"https://api.github.com/repos/ContinuumIO/dask/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ContinuumIO/dask/merges","archive_url":"https://api.github.com/repos/ContinuumIO/dask/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ContinuumIO/dask/downloads","issues_url":"https://api.github.com/repos/ContinuumIO/dask/issues{/number}","pulls_url":"https://api.github.com/repos/ContinuumIO/dask/pulls{/number}","milestones_url":"https://api.github.com/repos/ContinuumIO/dask/milestones{/number}","notifications_url":"https://api.github.com/repos/ContinuumIO/dask/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ContinuumIO/dask/labels{/name}","releases_url":"https://api.github.com/repos/ContinuumIO/dask/releases{/id}","created_at":"2015-01-04T18:50:00Z","updated_at":"2015-01-19T15:11:27Z","pushed_at":"2015-01-16T18:58:26Z","git_url":"git://github.com/ContinuumIO/dask.git","ssh_url":"git@github.com:ContinuumIO/dask.git","clone_url":"https://github.com/ContinuumIO/dask.git","svn_url":"https://github.com/ContinuumIO/dask","homepage":"","size":885,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":6,"forks":2,"open_issues":6,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ContinuumIO/dask/pulls/10"},"html":{"href":"https://github.com/ContinuumIO/dask/pull/10"},"issue":{"href":"https://api.github.com/repos/ContinuumIO/dask/issues/10"},"comments":{"href":"https://api.github.com/repos/ContinuumIO/dask/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/ContinuumIO/dask/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/ContinuumIO/dask/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ContinuumIO/dask/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/ContinuumIO/dask/statuses/67b6d05af60b1e50646857eb890038c8e5c29592"}}}}