{"action":"created","comment":{"url":"https://api.github.com/repos/dask/dask/pulls/comments/61277717","id":61277717,"diff_hunk":"@@ -0,0 +1,156 @@\n+import io\n+import sys\n+\n+from toolz import merge\n+\n+from .compression import seekable_files, files as cfiles\n+from .utils import SeekableFile\n+from ..delayed import delayed\n+from ..utils import system_encoding\n+\n+delayed = delayed(pure=True)\n+\n+_read_bytes = dict()\n+_open_files = dict()\n+_open_text_files = dict()\n+\n+\n+def read_bytes(path, delimiter=None, not_zero=False, blocksize=2**27,\n+                     sample=True, compression=None, **kwargs):\n+    \"\"\" Convert path to a list of delayed values\n+\n+    The path may be a filename like ``'2015-01-01.csv'`` or a globstring\n+    like ``'2015-*-*.csv'``.\n+\n+    The path may be preceeded by a protocol, like ``s3://`` or ``hdfs://`` and,\n+    if those libraries are installed, the futures will point to those locations\n+    instead.\n+\n+    This cleanly breaks data by a delimiter if given, so that block boundaries\n+    start directly after a delimiter and end on the delimiter.\n+\n+    Parameters\n+    ----------\n+    path: string\n+    delimiter: bytes\n+        An optional delimiter, like ``b'\\n'`` on which to split blocks of bytes\n+    not_zero: force seek of start-of-file delimiter, discarding header\n+    blocksize: int (=128MB)\n+        Chunk size\n+    compression: string or None\n+        String like 'gzip' or 'xz'.  Must support efficient random access.\n+    sample: bool, int\n+        Whether or not to return a sample from the first 10k bytes\n+    **kwargs: dict\n+        Options to send down to backend.  Includes authentication information\n+        for systems like S3 or HDFS\n+\n+    Examples\n+    --------\n+    >>> sample, blocks = read_bytes('2015-*-*.csv', delimiter=b'\\\\n')  # doctest: +SKIP","path":"dask/bytes/core.py","position":50,"original_position":50,"commit_id":"34a4e12714f09c49bf639fed72820f2f1849e586","original_commit_id":"34a4e12714f09c49bf639fed72820f2f1849e586","user":{"login":"martindurant","id":6042212,"avatar_url":"https://avatars.githubusercontent.com/u/6042212?v=3","gravatar_id":"","url":"https://api.github.com/users/martindurant","html_url":"https://github.com/martindurant","followers_url":"https://api.github.com/users/martindurant/followers","following_url":"https://api.github.com/users/martindurant/following{/other_user}","gists_url":"https://api.github.com/users/martindurant/gists{/gist_id}","starred_url":"https://api.github.com/users/martindurant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martindurant/subscriptions","organizations_url":"https://api.github.com/users/martindurant/orgs","repos_url":"https://api.github.com/users/martindurant/repos","events_url":"https://api.github.com/users/martindurant/events{/privacy}","received_events_url":"https://api.github.com/users/martindurant/received_events","type":"User","site_admin":false},"body":"Not `b'\\n'` ?","created_at":"2016-04-27T15:18:17Z","updated_at":"2016-04-27T15:18:17Z","html_url":"https://github.com/dask/dask/pull/1116#discussion_r61277717","pull_request_url":"https://api.github.com/repos/dask/dask/pulls/1116","_links":{"self":{"href":"https://api.github.com/repos/dask/dask/pulls/comments/61277717"},"html":{"href":"https://github.com/dask/dask/pull/1116#discussion_r61277717"},"pull_request":{"href":"https://api.github.com/repos/dask/dask/pulls/1116"}}},"pull_request":{"url":"https://api.github.com/repos/dask/dask/pulls/1116","id":67617325,"html_url":"https://github.com/dask/dask/pull/1116","diff_url":"https://github.com/dask/dask/pull/1116.diff","patch_url":"https://github.com/dask/dask/pull/1116.patch","issue_url":"https://api.github.com/repos/dask/dask/issues/1116","number":1116,"state":"open","locked":false,"title":"Refactor data ingest and read_csv","user":{"login":"mrocklin","id":306380,"avatar_url":"https://avatars.githubusercontent.com/u/306380?v=3","gravatar_id":"","url":"https://api.github.com/users/mrocklin","html_url":"https://github.com/mrocklin","followers_url":"https://api.github.com/users/mrocklin/followers","following_url":"https://api.github.com/users/mrocklin/following{/other_user}","gists_url":"https://api.github.com/users/mrocklin/gists{/gist_id}","starred_url":"https://api.github.com/users/mrocklin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrocklin/subscriptions","organizations_url":"https://api.github.com/users/mrocklin/orgs","repos_url":"https://api.github.com/users/mrocklin/repos","events_url":"https://api.github.com/users/mrocklin/events{/privacy}","received_events_url":"https://api.github.com/users/mrocklin/received_events","type":"User","site_admin":false},"body":"We refactor how data gets ingested from different sources.\r\n\r\n### Locations\r\n\r\nSystems like local, s3, and hdfs (will be in `distributed` repo) implement functions `read_bytes`, `open_files` and, if available, `open_text_files`.\r\n\r\n```python\r\n>>> sample, values = read_bytes('mydata.*.csv', delimiter=b'\\n', blocksize=1000)\r\n>>> sample\r\nb'name,amount,id\\nAlice,100,1\\n...'\r\n>>> values\r\n[[Delayed('mydata.1.csv-0-1000'), Delayed('mydata-1.csv-1000-2000')],\r\n [Delayed('mydata.1.csv-0-1000')],\r\n ...\r\n]\r\n\r\n>>> files = open_files('mydata.*.csv')\r\n>>> files = compute(*files)\r\n>>> next(files[0])\r\nb'name,amount,id\\nAlice,100,1\\n...'\r\n\r\n>>> files = open_text_files('mydata.*.csv', encoding='utf-8')\r\n>>> files = compute(*files)\r\n>>> next(files[0])\r\n'name,amount,id\\nAlice,100,1\\n...'\r\n```\r\n\r\nThere is a `bytes.core.{read_bytes,open_files,open_text_files}` function that intelligently dispatches to the correct location based on protocol.  `dd.read_csv('s3://bucket/myfiles.*.csv')` correctly dispatches to `bytes.s3.read_bytes`.\r\n\r\n### Compression\r\n\r\nWe have a variety of compression formats filled out and rely heavily on File-like objects found in those libraries.  If such a file-like object is registered then all of the `read_bytes` and `open_files` functions support that compression automatically.   If that file object is seekable then we can use `blocksize=` options to split data.  Again, this all happens automatically.  There is no need for downstream code to care about it\r\n\r\n### Formats\r\n\r\nWe've hooked this in to back both `dd.read_csv` and `db.read_text` with good success.  They get extra locations and compression for free.\r\n\r\ncc @jcrist cc @wabu I'd love review on this before I move forward much more.  @wabu in particular if you can tear holes in this I'd love to know sooner rather than later.","created_at":"2016-04-23T20:16:38Z","updated_at":"2016-04-27T15:18:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1328bcbd6c4a78e19b9b2cf532c0205199c5e547","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dask/dask/pulls/1116/commits","review_comments_url":"https://api.github.com/repos/dask/dask/pulls/1116/comments","review_comment_url":"https://api.github.com/repos/dask/dask/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dask/dask/issues/1116/comments","statuses_url":"https://api.github.com/repos/dask/dask/statuses/34a4e12714f09c49bf639fed72820f2f1849e586","head":{"label":"mrocklin:bytes","ref":"bytes","sha":"34a4e12714f09c49bf639fed72820f2f1849e586","user":{"login":"mrocklin","id":306380,"avatar_url":"https://avatars.githubusercontent.com/u/306380?v=3","gravatar_id":"","url":"https://api.github.com/users/mrocklin","html_url":"https://github.com/mrocklin","followers_url":"https://api.github.com/users/mrocklin/followers","following_url":"https://api.github.com/users/mrocklin/following{/other_user}","gists_url":"https://api.github.com/users/mrocklin/gists{/gist_id}","starred_url":"https://api.github.com/users/mrocklin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrocklin/subscriptions","organizations_url":"https://api.github.com/users/mrocklin/orgs","repos_url":"https://api.github.com/users/mrocklin/repos","events_url":"https://api.github.com/users/mrocklin/events{/privacy}","received_events_url":"https://api.github.com/users/mrocklin/received_events","type":"User","site_admin":false},"repo":{"id":28313768,"name":"dask","full_name":"mrocklin/dask","owner":{"login":"mrocklin","id":306380,"avatar_url":"https://avatars.githubusercontent.com/u/306380?v=3","gravatar_id":"","url":"https://api.github.com/users/mrocklin","html_url":"https://github.com/mrocklin","followers_url":"https://api.github.com/users/mrocklin/followers","following_url":"https://api.github.com/users/mrocklin/following{/other_user}","gists_url":"https://api.github.com/users/mrocklin/gists{/gist_id}","starred_url":"https://api.github.com/users/mrocklin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrocklin/subscriptions","organizations_url":"https://api.github.com/users/mrocklin/orgs","repos_url":"https://api.github.com/users/mrocklin/repos","events_url":"https://api.github.com/users/mrocklin/events{/privacy}","received_events_url":"https://api.github.com/users/mrocklin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mrocklin/dask","description":"Task scheduling and blocked algorithms for parallel processing","fork":true,"url":"https://api.github.com/repos/mrocklin/dask","forks_url":"https://api.github.com/repos/mrocklin/dask/forks","keys_url":"https://api.github.com/repos/mrocklin/dask/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mrocklin/dask/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mrocklin/dask/teams","hooks_url":"https://api.github.com/repos/mrocklin/dask/hooks","issue_events_url":"https://api.github.com/repos/mrocklin/dask/issues/events{/number}","events_url":"https://api.github.com/repos/mrocklin/dask/events","assignees_url":"https://api.github.com/repos/mrocklin/dask/assignees{/user}","branches_url":"https://api.github.com/repos/mrocklin/dask/branches{/branch}","tags_url":"https://api.github.com/repos/mrocklin/dask/tags","blobs_url":"https://api.github.com/repos/mrocklin/dask/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mrocklin/dask/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mrocklin/dask/git/refs{/sha}","trees_url":"https://api.github.com/repos/mrocklin/dask/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mrocklin/dask/statuses/{sha}","languages_url":"https://api.github.com/repos/mrocklin/dask/languages","stargazers_url":"https://api.github.com/repos/mrocklin/dask/stargazers","contributors_url":"https://api.github.com/repos/mrocklin/dask/contributors","subscribers_url":"https://api.github.com/repos/mrocklin/dask/subscribers","subscription_url":"https://api.github.com/repos/mrocklin/dask/subscription","commits_url":"https://api.github.com/repos/mrocklin/dask/commits{/sha}","git_commits_url":"https://api.github.com/repos/mrocklin/dask/git/commits{/sha}","comments_url":"https://api.github.com/repos/mrocklin/dask/comments{/number}","issue_comment_url":"https://api.github.com/repos/mrocklin/dask/issues/comments{/number}","contents_url":"https://api.github.com/repos/mrocklin/dask/contents/{+path}","compare_url":"https://api.github.com/repos/mrocklin/dask/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mrocklin/dask/merges","archive_url":"https://api.github.com/repos/mrocklin/dask/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mrocklin/dask/downloads","issues_url":"https://api.github.com/repos/mrocklin/dask/issues{/number}","pulls_url":"https://api.github.com/repos/mrocklin/dask/pulls{/number}","milestones_url":"https://api.github.com/repos/mrocklin/dask/milestones{/number}","notifications_url":"https://api.github.com/repos/mrocklin/dask/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mrocklin/dask/labels{/name}","releases_url":"https://api.github.com/repos/mrocklin/dask/releases{/id}","deployments_url":"https://api.github.com/repos/mrocklin/dask/deployments","created_at":"2014-12-21T21:26:56Z","updated_at":"2016-02-27T22:14:40Z","pushed_at":"2016-04-26T23:15:44Z","git_url":"git://github.com/mrocklin/dask.git","ssh_url":"git@github.com:mrocklin/dask.git","clone_url":"https://github.com/mrocklin/dask.git","svn_url":"https://github.com/mrocklin/dask","homepage":"","size":10104,"stargazers_count":11,"watchers_count":11,"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":11,"default_branch":"master"}},"base":{"label":"dask:master","ref":"master","sha":"5d94595499ebf0dd7b7bfcccca328f7d0fca7b7e","user":{"login":"dask","id":17131925,"avatar_url":"https://avatars.githubusercontent.com/u/17131925?v=3","gravatar_id":"","url":"https://api.github.com/users/dask","html_url":"https://github.com/dask","followers_url":"https://api.github.com/users/dask/followers","following_url":"https://api.github.com/users/dask/following{/other_user}","gists_url":"https://api.github.com/users/dask/gists{/gist_id}","starred_url":"https://api.github.com/users/dask/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dask/subscriptions","organizations_url":"https://api.github.com/users/dask/orgs","repos_url":"https://api.github.com/users/dask/repos","events_url":"https://api.github.com/users/dask/events{/privacy}","received_events_url":"https://api.github.com/users/dask/received_events","type":"Organization","site_admin":false},"repo":{"id":28782747,"name":"dask","full_name":"dask/dask","owner":{"login":"dask","id":17131925,"avatar_url":"https://avatars.githubusercontent.com/u/17131925?v=3","gravatar_id":"","url":"https://api.github.com/users/dask","html_url":"https://github.com/dask","followers_url":"https://api.github.com/users/dask/followers","following_url":"https://api.github.com/users/dask/following{/other_user}","gists_url":"https://api.github.com/users/dask/gists{/gist_id}","starred_url":"https://api.github.com/users/dask/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dask/subscriptions","organizations_url":"https://api.github.com/users/dask/orgs","repos_url":"https://api.github.com/users/dask/repos","events_url":"https://api.github.com/users/dask/events{/privacy}","received_events_url":"https://api.github.com/users/dask/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dask/dask","description":"Task scheduling and blocked algorithms for parallel processing","fork":false,"url":"https://api.github.com/repos/dask/dask","forks_url":"https://api.github.com/repos/dask/dask/forks","keys_url":"https://api.github.com/repos/dask/dask/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dask/dask/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dask/dask/teams","hooks_url":"https://api.github.com/repos/dask/dask/hooks","issue_events_url":"https://api.github.com/repos/dask/dask/issues/events{/number}","events_url":"https://api.github.com/repos/dask/dask/events","assignees_url":"https://api.github.com/repos/dask/dask/assignees{/user}","branches_url":"https://api.github.com/repos/dask/dask/branches{/branch}","tags_url":"https://api.github.com/repos/dask/dask/tags","blobs_url":"https://api.github.com/repos/dask/dask/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dask/dask/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dask/dask/git/refs{/sha}","trees_url":"https://api.github.com/repos/dask/dask/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dask/dask/statuses/{sha}","languages_url":"https://api.github.com/repos/dask/dask/languages","stargazers_url":"https://api.github.com/repos/dask/dask/stargazers","contributors_url":"https://api.github.com/repos/dask/dask/contributors","subscribers_url":"https://api.github.com/repos/dask/dask/subscribers","subscription_url":"https://api.github.com/repos/dask/dask/subscription","commits_url":"https://api.github.com/repos/dask/dask/commits{/sha}","git_commits_url":"https://api.github.com/repos/dask/dask/git/commits{/sha}","comments_url":"https://api.github.com/repos/dask/dask/comments{/number}","issue_comment_url":"https://api.github.com/repos/dask/dask/issues/comments{/number}","contents_url":"https://api.github.com/repos/dask/dask/contents/{+path}","compare_url":"https://api.github.com/repos/dask/dask/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dask/dask/merges","archive_url":"https://api.github.com/repos/dask/dask/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dask/dask/downloads","issues_url":"https://api.github.com/repos/dask/dask/issues{/number}","pulls_url":"https://api.github.com/repos/dask/dask/pulls{/number}","milestones_url":"https://api.github.com/repos/dask/dask/milestones{/number}","notifications_url":"https://api.github.com/repos/dask/dask/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dask/dask/labels{/name}","releases_url":"https://api.github.com/repos/dask/dask/releases{/id}","deployments_url":"https://api.github.com/repos/dask/dask/deployments","created_at":"2015-01-04T18:50:00Z","updated_at":"2016-04-27T06:18:02Z","pushed_at":"2016-04-26T23:16:47Z","git_url":"git://github.com/dask/dask.git","ssh_url":"git@github.com:dask/dask.git","clone_url":"https://github.com/dask/dask.git","svn_url":"https://github.com/dask/dask","homepage":"http://dask.pydata.org","size":11039,"stargazers_count":675,"watchers_count":675,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":101,"mirror_url":null,"open_issues_count":50,"forks":101,"open_issues":50,"watchers":675,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dask/dask/pulls/1116"},"html":{"href":"https://github.com/dask/dask/pull/1116"},"issue":{"href":"https://api.github.com/repos/dask/dask/issues/1116"},"comments":{"href":"https://api.github.com/repos/dask/dask/issues/1116/comments"},"review_comments":{"href":"https://api.github.com/repos/dask/dask/pulls/1116/comments"},"review_comment":{"href":"https://api.github.com/repos/dask/dask/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dask/dask/pulls/1116/commits"},"statuses":{"href":"https://api.github.com/repos/dask/dask/statuses/34a4e12714f09c49bf639fed72820f2f1849e586"}}}}