From c45e445e9fe6bd264aba5a1736f0145ca7bdacc9 Mon Sep 17 00:00:00 2001 From: Mathieu Sornay Date: Wed, 31 Jan 2018 16:58:56 +0100 Subject: BUG: fromregex: asbytes called on regexp objects When calling fromregex() with a binary stream and a regular expression object, asbytes() was called on the regexp object, resulting in an incorrect regular expression being compiled and used. --- numpy/lib/tests/test_io.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'numpy/lib/tests') diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index a274636da..277569e10 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: -- cgit v1.2.1