summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2018-05-30 18:52:03 -0600
committerGitHub <noreply@github.com>2018-05-30 18:52:03 -0600
commita4653902cd6ad01c5051deb5c09fae315b1b4a1b (patch)
treeebe6b6d9dee197b39f183c870269e678faee26a0 /numpy
parent9e2dd688acffbe949cfd615f43cb79fa3ceeb231 (diff)
parent0c4ebf1cd396f3cfa1e218b2a0e46f1bc84f9614 (diff)
downloadnumpy-a4653902cd6ad01c5051deb5c09fae315b1b4a1b.tar.gz
Merge pull request #11200 from ahaldane/fix_genfromtxt_delimiter_encoding
BUG: delimiter/comments in genfromtxt should be encoded
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/_iotools.py4
-rw-r--r--numpy/lib/tests/test__iotools.py5
2 files changed, 9 insertions, 0 deletions
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py
index 27143e5c6..b604b8c52 100644
--- a/numpy/lib/_iotools.py
+++ b/numpy/lib/_iotools.py
@@ -205,7 +205,11 @@ class LineSplitter(object):
#
def __init__(self, delimiter=None, comments='#', autostrip=True, encoding=None):
+ delimiter = _decode_line(delimiter)
+ comments = _decode_line(comments)
+
self.comments = comments
+
# Delimiter is a character
if (delimiter is None) or isinstance(delimiter, basestring):
delimiter = delimiter or None
diff --git a/numpy/lib/tests/test__iotools.py b/numpy/lib/tests/test__iotools.py
index 5f6c29a4d..b4888f1bd 100644
--- a/numpy/lib/tests/test__iotools.py
+++ b/numpy/lib/tests/test__iotools.py
@@ -53,6 +53,11 @@ class TestLineSplitter(object):
test = LineSplitter(',')(strg)
assert_equal(test, ['1', '2', '3', '4', '', '5'])
+ # gh-11028 bytes comment/delimiters should get encoded
+ strg = b" 1,2,3,4,,5 % test"
+ test = LineSplitter(delimiter=b',', comments=b'%')(strg)
+ assert_equal(test, ['1', '2', '3', '4', '', '5'])
+
def test_constant_fixed_width(self):
"Test LineSplitter w/ fixed-width fields"
strg = " 1 2 3 4 5 # test"