summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
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: