summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2018-02-20 00:08:00 -0800
committerGitHub <noreply@github.com>2018-02-20 00:08:00 -0800
commit7ed541ce3a91eeeb951d9e5b000cd68ebbda794c (patch)
tree0bf18c04f08eff16ee69103e34365a4822a49820 /numpy/lib
parent71555c48be7f07833bd540dacb50deb8069b551f (diff)
parentc45e445e9fe6bd264aba5a1736f0145ca7bdacc9 (diff)
downloadnumpy-7ed541ce3a91eeeb951d9e5b000cd68ebbda794c.tar.gz
Merge pull request #10501 from msornay/fromregex-bytes
BUG: fromregex: asbytes called on regexp objects
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/npyio.py4
-rw-r--r--numpy/lib/tests/test_io.py9
2 files changed, 10 insertions, 3 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 73613d2a4..959574594 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -1465,9 +1465,9 @@ def fromregex(file, regexp, dtype, encoding=None):
dtype = np.dtype(dtype)
content = file.read()
- if isinstance(content, bytes) and not isinstance(regexp, bytes):
+ if isinstance(content, bytes) and isinstance(regexp, np.unicode):
regexp = asbytes(regexp)
- elif not isinstance(content, bytes) and isinstance(regexp, bytes):
+ elif isinstance(content, np.unicode) and isinstance(regexp, bytes):
regexp = asstr(regexp)
if not hasattr(regexp, 'match'):
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index d05fcd543..ae40cf73b 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -1073,6 +1073,13 @@ class Testfromregex(object):
x = np.fromregex(path, regexp, dt, encoding='UTF-8')
assert_array_equal(x, a)
+ def test_compiled_bytes(self):
+ regexp = re.compile(b'(\\d)')
+ c = BytesIO(b'123')
+ dt = [('num', np.float64)]
+ a = np.array([1, 2, 3], dtype=dt)
+ x = np.fromregex(c, regexp, dt)
+ assert_array_equal(x, a)
#####--------------------------------------------------------------------------
@@ -1982,7 +1989,7 @@ M 33 21.99
utf8.encode(encoding)
except (UnicodeError, ImportError):
raise SkipTest('Skipping test_utf8_file_nodtype_unicode, '
- 'unable to encode utf8 in preferred encoding')
+ 'unable to encode utf8 in preferred encoding')
with temppath() as path:
with io.open(path, "wt") as f: