Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
248 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from ..utils import ignoring | ||
from .core import read_bytes, open_files, open_text_files | ||
|
||
from . import local | ||
|
||
with ignoring(ImportError, SyntaxError): | ||
from . import s3 | ||
with ignoring(ImportError): | ||
from . import local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import io | ||
|
||
from dask.bytes.utils import read_block, seek_delimiter | ||
|
||
|
||
def test_read_block(): | ||
delimiter = b'\n' | ||
data = delimiter.join([b'123', b'456', b'789']) | ||
f = io.BytesIO(data) | ||
|
||
assert read_block(f, 1, 2) == b'23' | ||
assert read_block(f, 0, 1, delimiter=b'\n') == b'123\n' | ||
assert read_block(f, 0, 2, delimiter=b'\n') == b'123\n' | ||
assert read_block(f, 0, 3, delimiter=b'\n') == b'123\n' | ||
assert read_block(f, 0, 5, delimiter=b'\n') == b'123\n456\n' | ||
assert read_block(f, 0, 8, delimiter=b'\n') == b'123\n456\n789' | ||
assert read_block(f, 0, 100, delimiter=b'\n') == b'123\n456\n789' | ||
assert read_block(f, 1, 1, delimiter=b'\n') == b'' | ||
assert read_block(f, 1, 5, delimiter=b'\n') == b'456\n' | ||
assert read_block(f, 1, 8, delimiter=b'\n') == b'456\n789' | ||
|
||
for ols in [[(0, 3), (3, 3), (6, 3), (9, 2)], | ||
[(0, 4), (4, 4), (8, 4)]]: | ||
out = [read_block(f, o, l, b'\n') for o, l in ols] | ||
assert b"".join(filter(None, out)) == data | ||
|
||
|
||
def test_seek_delimiter_endline(): | ||
f = io.BytesIO(b'123\n456\n789') | ||
|
||
# if at zero, stay at zero | ||
seek_delimiter(f, b'\n', 5) | ||
assert f.tell() == 0 | ||
|
||
# choose the first block | ||
for bs in [1, 5, 100]: | ||
f.seek(1) | ||
seek_delimiter(f, b'\n', blocksize=bs) | ||
assert f.tell() == 4 | ||
|
||
# handle long delimiters well, even with short blocksizes | ||
f = io.BytesIO(b'123abc456abc789') | ||
for bs in [1, 2, 3, 4, 5, 6, 10]: | ||
f.seek(1) | ||
seek_delimiter(f, b'abc', blocksize=bs) | ||
assert f.tell() == 6 | ||
|
||
# End at the end | ||
f = io.BytesIO(b'123\n456') | ||
f.seek(5) | ||
seek_delimiter(f, b'\n', 5) | ||
assert f.tell() == 7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.