summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/_internal.py31
-rw-r--r--numpy/core/memmap.py2
-rw-r--r--numpy/core/tests/test_datetime.py25
-rw-r--r--numpy/core/tests/test_defchararray.py40
-rw-r--r--numpy/core/tests/test_multiarray.py94
-rw-r--r--numpy/core/tests/test_nditer.py4
-rw-r--r--numpy/core/tests/test_numerictypes.py6
-rw-r--r--numpy/core/tests/test_records.py17
-rw-r--r--numpy/core/tests/test_regression.py82
-rw-r--r--numpy/core/tests/test_ufunc.py5
-rw-r--r--numpy/core/tests/test_unicode.py4
11 files changed, 153 insertions, 157 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index d73cdcc55..11a13026b 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -9,15 +9,15 @@ from __future__ import division, absolute_import, print_function
import re
import sys
-from numpy.compat import asbytes, basestring
+from numpy.compat import basestring
from .multiarray import dtype, array, ndarray
import ctypes
from .numerictypes import object_
if (sys.byteorder == 'little'):
- _nbo = asbytes('<')
+ _nbo = b'<'
else:
- _nbo = asbytes('>')
+ _nbo = b'>'
def _makenames_list(adict, align):
allfields = []
@@ -136,17 +136,16 @@ def _reconstruct(subtype, shape, dtype):
# format_re was originally from numarray by J. Todd Miller
-format_re = re.compile(asbytes(
- r'(?P<order1>[<>|=]?)'
- r'(?P<repeats> *[(]?[ ,0-9L]*[)]? *)'
- r'(?P<order2>[<>|=]?)'
- r'(?P<dtype>[A-Za-z0-9.?]*(?:\[[a-zA-Z0-9,.]+\])?)'))
-sep_re = re.compile(asbytes(r'\s*,\s*'))
-space_re = re.compile(asbytes(r'\s+$'))
+format_re = re.compile(br'(?P<order1>[<>|=]?)'
+ br'(?P<repeats> *[(]?[ ,0-9L]*[)]? *)'
+ br'(?P<order2>[<>|=]?)'
+ br'(?P<dtype>[A-Za-z0-9.?]*(?:\[[a-zA-Z0-9,.]+\])?)')
+sep_re = re.compile(br'\s*,\s*')
+space_re = re.compile(br'\s+$')
# astr is a string (perhaps comma separated)
-_convorder = {asbytes('='): _nbo}
+_convorder = {b'=': _nbo}
def _commastring(astr):
startindex = 0
@@ -171,9 +170,9 @@ def _commastring(astr):
(len(result)+1, astr))
startindex = mo.end()
- if order2 == asbytes(''):
+ if order2 == b'':
order = order1
- elif order1 == asbytes(''):
+ elif order1 == b'':
order = order2
else:
order1 = _convorder.get(order1, order1)
@@ -184,10 +183,10 @@ def _commastring(astr):
(order1, order2))
order = order1
- if order in [asbytes('|'), asbytes('='), _nbo]:
- order = asbytes('')
+ if order in [b'|', b'=', _nbo]:
+ order = b''
dtype = order + dtype
- if (repeats == asbytes('')):
+ if (repeats == b''):
newitem = dtype
else:
newitem = (dtype, eval(repeats))
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index f07cf78ee..4604cc734 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -248,7 +248,7 @@ class memmap(ndarray):
if mode == 'w+' or (mode == 'r+' and flen < bytes):
fid.seek(bytes - 1, 0)
- fid.write(np.compat.asbytes('\0'))
+ fid.write(b'\0')
fid.flush()
if mode == 'c':
diff --git a/numpy/core/tests/test_datetime.py b/numpy/core/tests/test_datetime.py
index 94391f84c..b5d096d47 100644
--- a/numpy/core/tests/test_datetime.py
+++ b/numpy/core/tests/test_datetime.py
@@ -5,7 +5,6 @@ import pickle
import numpy
import numpy as np
import datetime
-from numpy.compat import asbytes
from numpy.testing import (
TestCase, run_module_suite, assert_, assert_equal, assert_raises,
assert_warns, dec, suppress_warnings
@@ -586,18 +585,18 @@ class TestDateTime(TestCase):
assert_equal(pickle.loads(pickle.dumps(dt)), dt)
# Check that loading pickles from 1.6 works
- pkl = "cnumpy\ndtype\np0\n(S'M8'\np1\nI0\nI1\ntp2\nRp3\n" + \
- "(I4\nS'<'\np4\nNNNI-1\nI-1\nI0\n((dp5\n(S'D'\np6\n" + \
- "I7\nI1\nI1\ntp7\ntp8\ntp9\nb."
- assert_equal(pickle.loads(asbytes(pkl)), np.dtype('<M8[7D]'))
- pkl = "cnumpy\ndtype\np0\n(S'M8'\np1\nI0\nI1\ntp2\nRp3\n" + \
- "(I4\nS'<'\np4\nNNNI-1\nI-1\nI0\n((dp5\n(S'W'\np6\n" + \
- "I1\nI1\nI1\ntp7\ntp8\ntp9\nb."
- assert_equal(pickle.loads(asbytes(pkl)), np.dtype('<M8[W]'))
- pkl = "cnumpy\ndtype\np0\n(S'M8'\np1\nI0\nI1\ntp2\nRp3\n" + \
- "(I4\nS'>'\np4\nNNNI-1\nI-1\nI0\n((dp5\n(S'us'\np6\n" + \
- "I1\nI1\nI1\ntp7\ntp8\ntp9\nb."
- assert_equal(pickle.loads(asbytes(pkl)), np.dtype('>M8[us]'))
+ pkl = b"cnumpy\ndtype\np0\n(S'M8'\np1\nI0\nI1\ntp2\nRp3\n" + \
+ b"(I4\nS'<'\np4\nNNNI-1\nI-1\nI0\n((dp5\n(S'D'\np6\n" + \
+ b"I7\nI1\nI1\ntp7\ntp8\ntp9\nb."
+ assert_equal(pickle.loads(pkl), np.dtype('<M8[7D]'))
+ pkl = b"cnumpy\ndtype\np0\n(S'M8'\np1\nI0\nI1\ntp2\nRp3\n" + \
+ b"(I4\nS'<'\np4\nNNNI-1\nI-1\nI0\n((dp5\n(S'W'\np6\n" + \
+ b"I1\nI1\nI1\ntp7\ntp8\ntp9\nb."
+ assert_equal(pickle.loads(pkl), np.dtype('<M8[W]'))
+ pkl = b"cnumpy\ndtype\np0\n(S'M8'\np1\nI0\nI1\ntp2\nRp3\n" + \
+ b"(I4\nS'>'\np4\nNNNI-1\nI-1\nI0\n((dp5\n(S'us'\np6\n" + \
+ b"I1\nI1\nI1\ntp7\ntp8\ntp9\nb."
+ assert_equal(pickle.loads(pkl), np.dtype('>M8[us]'))
def test_setstate(self):
"Verify that datetime dtype __setstate__ can handle bad arguments"
diff --git a/numpy/core/tests/test_defchararray.py b/numpy/core/tests/test_defchararray.py
index e828b879f..3e0eebc91 100644
--- a/numpy/core/tests/test_defchararray.py
+++ b/numpy/core/tests/test_defchararray.py
@@ -71,7 +71,7 @@ class TestBasic(TestCase):
assert_(issubclass((A + B).dtype.type, np.unicode_))
def test_from_string(self):
- A = np.char.array(asbytes('abc'))
+ A = np.char.array(b'abc')
assert_equal(len(A), 1)
assert_equal(len(A[0]), 3)
assert_(issubclass(A.dtype.type, np.string_))
@@ -155,7 +155,7 @@ class TestChar(TestCase):
def test_it(self):
assert_equal(self.A.shape, (4,))
- assert_equal(self.A.upper()[:2].tobytes(), asbytes('AB'))
+ assert_equal(self.A.upper()[:2].tobytes(), b'AB')
class TestComparisons(TestCase):
def setUp(self):
@@ -332,11 +332,11 @@ class TestMethods(TestCase):
C = self.A.center([10, 20])
assert_array_equal(np.char.str_len(C), [[10, 20], [10, 20], [12, 20]])
- C = self.A.center(20, asbytes('#'))
- assert_(np.all(C.startswith(asbytes('#'))))
- assert_(np.all(C.endswith(asbytes('#'))))
+ C = self.A.center(20, b'#')
+ assert_(np.all(C.startswith(b'#')))
+ assert_(np.all(C.endswith(b'#')))
- C = np.char.center(asbytes('FOO'), [[10, 20], [15, 8]])
+ C = np.char.center(b'FOO', [[10, 20], [15, 8]])
tgt = asbytes_nested([[' FOO ', ' FOO '],
[' FOO ', ' FOO ']])
assert_(issubclass(C.dtype.type, np.string_))
@@ -344,7 +344,7 @@ class TestMethods(TestCase):
def test_decode(self):
if sys.version_info[0] >= 3:
- A = np.char.array([asbytes('\\u03a3')])
+ A = np.char.array([b'\\u03a3'])
assert_(A.decode('unicode-escape')[0] == '\u03a3')
else:
A = np.char.array(['736563726574206d657373616765'])
@@ -356,7 +356,7 @@ class TestMethods(TestCase):
def test_expandtabs(self):
T = self.A.expandtabs()
- assert_(T[2, 0] == asbytes('123 345 \0'))
+ assert_(T[2, 0] == b'123 345 \0')
def test_join(self):
if sys.version_info[0] >= 3:
@@ -382,12 +382,12 @@ class TestMethods(TestCase):
C = self.A.ljust([10, 20])
assert_array_equal(np.char.str_len(C), [[10, 20], [10, 20], [12, 20]])
- C = self.A.ljust(20, asbytes('#'))
- assert_array_equal(C.startswith(asbytes('#')), [
+ C = self.A.ljust(20, b'#')
+ assert_array_equal(C.startswith(b'#'), [
[False, True], [False, False], [False, False]])
- assert_(np.all(C.endswith(asbytes('#'))))
+ assert_(np.all(C.endswith(b'#')))
- C = np.char.ljust(asbytes('FOO'), [[10, 20], [15, 8]])
+ C = np.char.ljust(b'FOO', [[10, 20], [15, 8]])
tgt = asbytes_nested([['FOO ', 'FOO '],
['FOO ', 'FOO ']])
assert_(issubclass(C.dtype.type, np.string_))
@@ -443,7 +443,7 @@ class TestMethods(TestCase):
if sys.version_info[0] < 3:
# NOTE: b'abc'.replace(b'a', 'b') is not allowed on Py3
- R = self.A.replace(asbytes('a'), sixu('\u03a3'))
+ R = self.A.replace(b'a', sixu('\u03a3'))
tgt = [[sixu(' \u03a3bc '), ''],
['12345', sixu('MixedC\u03a3se')],
['123 \t 345 \x00', 'UPPER']]
@@ -456,12 +456,12 @@ class TestMethods(TestCase):
C = self.A.rjust([10, 20])
assert_array_equal(np.char.str_len(C), [[10, 20], [10, 20], [12, 20]])
- C = self.A.rjust(20, asbytes('#'))
- assert_(np.all(C.startswith(asbytes('#'))))
- assert_array_equal(C.endswith(asbytes('#')),
+ C = self.A.rjust(20, b'#')
+ assert_(np.all(C.startswith(b'#')))
+ assert_array_equal(C.endswith(b'#'),
[[False, True], [False, False], [False, False]])
- C = np.char.rjust(asbytes('FOO'), [[10, 20], [15, 8]])
+ C = np.char.rjust(b'FOO', [[10, 20], [15, 8]])
tgt = asbytes_nested([[' FOO', ' FOO'],
[' FOO', ' FOO']])
assert_(issubclass(C.dtype.type, np.string_))
@@ -476,7 +476,7 @@ class TestMethods(TestCase):
assert_array_equal(P, tgt)
def test_rsplit(self):
- A = self.A.rsplit(asbytes('3'))
+ A = self.A.rsplit(b'3')
tgt = asbytes_nested([[[' abc '], ['']],
[['12', '45'], ['MixedCase']],
[['12', ' \t ', '45 \x00 '], ['UPPER']]])
@@ -522,7 +522,7 @@ class TestMethods(TestCase):
assert_array_equal(self.B.strip(), tgt)
def test_split(self):
- A = self.A.split(asbytes('3'))
+ A = self.A.split(b'3')
tgt = asbytes_nested([
[[' abc '], ['']],
[['12', '45'], ['MixedCase']],
@@ -688,7 +688,7 @@ class TestOperations(TestCase):
assert_(sl2.base is arr)
assert_(sl2.base.base is arr.base)
- assert_(arr[0, 0] == asbytes('abc'))
+ assert_(arr[0, 0] == b'abc')
def test_empty_indexing():
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index b780c5558..ac84014a9 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -20,7 +20,7 @@ from decimal import Decimal
import numpy as np
-from numpy.compat import asbytes, getexception, strchar, unicode, sixu
+from numpy.compat import getexception, strchar, unicode, sixu
from test_print import in_foreign_locale
from numpy.core.multiarray_tests import (
test_neighborhood_iterator, test_neighborhood_iterator_oob,
@@ -3159,46 +3159,46 @@ class TestPickling(TestCase):
# version 0 pickles, using protocol=2 to pickle
# version 0 doesn't have a version field
def test_version0_int8(self):
- s = '\x80\x02cnumpy.core._internal\n_reconstruct\nq\x01cnumpy\nndarray\nq\x02K\x00\x85U\x01b\x87Rq\x03(K\x04\x85cnumpy\ndtype\nq\x04U\x02i1K\x00K\x01\x87Rq\x05(U\x01|NNJ\xff\xff\xff\xffJ\xff\xff\xff\xfftb\x89U\x04\x01\x02\x03\x04tb.'
+ s = b'\x80\x02cnumpy.core._internal\n_reconstruct\nq\x01cnumpy\nndarray\nq\x02K\x00\x85U\x01b\x87Rq\x03(K\x04\x85cnumpy\ndtype\nq\x04U\x02i1K\x00K\x01\x87Rq\x05(U\x01|NNJ\xff\xff\xff\xffJ\xff\xff\xff\xfftb\x89U\x04\x01\x02\x03\x04tb.'
a = np.array([1, 2, 3, 4], dtype=np.int8)
- p = self._loads(asbytes(s))
+ p = self._loads(s)
assert_equal(a, p)
def test_version0_float32(self):
- s = '\x80\x02cnumpy.core._internal\n_reconstruct\nq\x01cnumpy\nndarray\nq\x02K\x00\x85U\x01b\x87Rq\x03(K\x04\x85cnumpy\ndtype\nq\x04U\x02f4K\x00K\x01\x87Rq\x05(U\x01<NNJ\xff\xff\xff\xffJ\xff\xff\xff\xfftb\x89U\x10\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@tb.'
+ s = b'\x80\x02cnumpy.core._internal\n_reconstruct\nq\x01cnumpy\nndarray\nq\x02K\x00\x85U\x01b\x87Rq\x03(K\x04\x85cnumpy\ndtype\nq\x04U\x02f4K\x00K\x01\x87Rq\x05(U\x01<NNJ\xff\xff\xff\xffJ\xff\xff\xff\xfftb\x89U\x10\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@tb.'
a = np.array([1.0, 2.0, 3.0, 4.0], dtype=np.float32)
- p = self._loads(asbytes(s))
+ p = self._loads(s)
assert_equal(a, p)
def test_version0_object(self):
- s = '\x80\x02cnumpy.core._internal\n_reconstruct\nq\x01cnumpy\nndarray\nq\x02K\x00\x85U\x01b\x87Rq\x03(K\x02\x85cnumpy\ndtype\nq\x04U\x02O8K\x00K\x01\x87Rq\x05(U\x01|NNJ\xff\xff\xff\xffJ\xff\xff\xff\xfftb\x89]q\x06(}q\x07U\x01aK\x01s}q\x08U\x01bK\x02setb.'
+ s = b'\x80\x02cnumpy.core._internal\n_reconstruct\nq\x01cnumpy\nndarray\nq\x02K\x00\x85U\x01b\x87Rq\x03(K\x02\x85cnumpy\ndtype\nq\x04U\x02O8K\x00K\x01\x87Rq\x05(U\x01|NNJ\xff\xff\xff\xffJ\xff\xff\xff\xfftb\x89]q\x06(}q\x07U\x01aK\x01s}q\x08U\x01bK\x02setb.'
a = np.array([{'a': 1}, {'b': 2}])
- p = self._loads(asbytes(s))
+ p = self._loads(s)
assert_equal(a, p)
# version 1 pickles, using protocol=2 to pickle
def test_version1_int8(self):
- s = '\x80\x02cnumpy.core._internal\n_reconstruct\nq\x01cnumpy\nndarray\nq\x02K\x00\x85U\x01b\x87Rq\x03(K\x01K\x04\x85cnumpy\ndtype\nq\x04U\x02i1K\x00K\x01\x87Rq\x05(K\x01U\x01|NNJ\xff\xff\xff\xffJ\xff\xff\xff\xfftb\x89U\x04\x01\x02\x03\x04tb.'
+ s = b'\x80\x02cnumpy.core._internal\n_reconstruct\nq\x01cnumpy\nndarray\nq\x02K\x00\x85U\x01b\x87Rq\x03(K\x01K\x04\x85cnumpy\ndtype\nq\x04U\x02i1K\x00K\x01\x87Rq\x05(K\x01U\x01|NNJ\xff\xff\xff\xffJ\xff\xff\xff\xfftb\x89U\x04\x01\x02\x03\x04tb.'
a = np.array([1, 2, 3, 4], dtype=np.int8)
- p = self._loads(asbytes(s))
+ p = self._loads(s)
assert_equal(a, p)
def test_version1_float32(self):
- s = '\x80\x02cnumpy.core._internal\n_reconstruct\nq\x01cnumpy\nndarray\nq\x02K\x00\x85U\x01b\x87Rq\x03(K\x01K\x04\x85cnumpy\ndtype\nq\x04U\x02f4K\x00K\x01\x87Rq\x05(K\x01U\x01<NNJ\xff\xff\xff\xffJ\xff\xff\xff\xfftb\x89U\x10\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@tb.'
+ s = b'\x80\x02cnumpy.core._internal\n_reconstruct\nq\x01cnumpy\nndarray\nq\x02K\x00\x85U\x01b\x87Rq\x03(K\x01K\x04\x85cnumpy\ndtype\nq\x04U\x02f4K\x00K\x01\x87Rq\x05(K\x01U\x01<NNJ\xff\xff\xff\xffJ\xff\xff\xff\xfftb\x89U\x10\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@tb.'
a = np.array([1.0, 2.0, 3.0, 4.0], dtype=np.float32)
- p = self._loads(asbytes(s))
+ p = self._loads(s)
assert_equal(a, p)
def test_version1_object(self):
- s = '\x80\x02cnumpy.core._internal\n_reconstruct\nq\x01cnumpy\nndarray\nq\x02K\x00\x85U\x01b\x87Rq\x03(K\x01K\x02\x85cnumpy\ndtype\nq\x04U\x02O8K\x00K\x01\x87Rq\x05(K\x01U\x01|NNJ\xff\xff\xff\xffJ\xff\xff\xff\xfftb\x89]q\x06(}q\x07U\x01aK\x01s}q\x08U\x01bK\x02setb.'
+ s = b'\x80\x02cnumpy.core._internal\n_reconstruct\nq\x01cnumpy\nndarray\nq\x02K\x00\x85U\x01b\x87Rq\x03(K\x01K\x02\x85cnumpy\ndtype\nq\x04U\x02O8K\x00K\x01\x87Rq\x05(K\x01U\x01|NNJ\xff\xff\xff\xffJ\xff\xff\xff\xfftb\x89]q\x06(}q\x07U\x01aK\x01s}q\x08U\x01bK\x02setb.'
a = np.array([{'a': 1}, {'b': 2}])
- p = self._loads(asbytes(s))
+ p = self._loads(s)
assert_equal(a, p)
def test_subarray_int_shape(self):
- s = "cnumpy.core.multiarray\n_reconstruct\np0\n(cnumpy\nndarray\np1\n(I0\ntp2\nS'b'\np3\ntp4\nRp5\n(I1\n(I1\ntp6\ncnumpy\ndtype\np7\n(S'V6'\np8\nI0\nI1\ntp9\nRp10\n(I3\nS'|'\np11\nN(S'a'\np12\ng3\ntp13\n(dp14\ng12\n(g7\n(S'V4'\np15\nI0\nI1\ntp16\nRp17\n(I3\nS'|'\np18\n(g7\n(S'i1'\np19\nI0\nI1\ntp20\nRp21\n(I3\nS'|'\np22\nNNNI-1\nI-1\nI0\ntp23\nb(I2\nI2\ntp24\ntp25\nNNI4\nI1\nI0\ntp26\nbI0\ntp27\nsg3\n(g7\n(S'V2'\np28\nI0\nI1\ntp29\nRp30\n(I3\nS'|'\np31\n(g21\nI2\ntp32\nNNI2\nI1\nI0\ntp33\nbI4\ntp34\nsI6\nI1\nI0\ntp35\nbI00\nS'\\x01\\x01\\x01\\x01\\x01\\x02'\np36\ntp37\nb."
+ s = b"cnumpy.core.multiarray\n_reconstruct\np0\n(cnumpy\nndarray\np1\n(I0\ntp2\nS'b'\np3\ntp4\nRp5\n(I1\n(I1\ntp6\ncnumpy\ndtype\np7\n(S'V6'\np8\nI0\nI1\ntp9\nRp10\n(I3\nS'|'\np11\nN(S'a'\np12\ng3\ntp13\n(dp14\ng12\n(g7\n(S'V4'\np15\nI0\nI1\ntp16\nRp17\n(I3\nS'|'\np18\n(g7\n(S'i1'\np19\nI0\nI1\ntp20\nRp21\n(I3\nS'|'\np22\nNNNI-1\nI-1\nI0\ntp23\nb(I2\nI2\ntp24\ntp25\nNNI4\nI1\nI0\ntp26\nbI0\ntp27\nsg3\n(g7\n(S'V2'\np28\nI0\nI1\ntp29\nRp30\n(I3\nS'|'\np31\n(g21\nI2\ntp32\nNNI2\nI1\nI0\ntp33\nbI4\ntp34\nsI6\nI1\nI0\ntp35\nbI00\nS'\\x01\\x01\\x01\\x01\\x01\\x02'\np36\ntp37\nb."
a = np.array([(1, (1, 2))], dtype=[('a', 'i1', (2, 2)), ('b', 'i1', 2)])
- p = self._loads(asbytes(s))
+ p = self._loads(s)
assert_equal(a, p)
@@ -4011,33 +4011,33 @@ class TestIO(object):
assert_equal(pos, 10, err_msg=err_msg)
def _check_from(self, s, value, **kw):
- y = np.fromstring(asbytes(s), **kw)
+ y = np.fromstring(s, **kw)
assert_array_equal(y, value)
f = open(self.filename, 'wb')
- f.write(asbytes(s))
+ f.write(s)
f.close()
y = np.fromfile(self.filename, **kw)
assert_array_equal(y, value)
def test_nan(self):
self._check_from(
- "nan +nan -nan NaN nan(foo) +NaN(BAR) -NAN(q_u_u_x_)",
+ b"nan +nan -nan NaN nan(foo) +NaN(BAR) -NAN(q_u_u_x_)",
[np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan],
sep=' ')
def test_inf(self):
self._check_from(
- "inf +inf -inf infinity -Infinity iNfInItY -inF",
+ b"inf +inf -inf infinity -Infinity iNfInItY -inF",
[np.inf, np.inf, -np.inf, np.inf, -np.inf, np.inf, -np.inf],
sep=' ')
def test_numbers(self):
- self._check_from("1.234 -1.234 .3 .3e55 -123133.1231e+133",
+ self._check_from(b"1.234 -1.234 .3 .3e55 -123133.1231e+133",
[1.234, -1.234, .3, .3e55, -123133.1231e+133], sep=' ')
def test_binary(self):
- self._check_from('\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@',
+ self._check_from(b'\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@',
np.array([1, 2, 3, 4]),
dtype='<f4')
@@ -4067,40 +4067,40 @@ class TestIO(object):
pass
def test_string(self):
- self._check_from('1,2,3,4', [1., 2., 3., 4.], sep=',')
+ self._check_from(b'1,2,3,4', [1., 2., 3., 4.], sep=',')
def test_counted_string(self):
- self._check_from('1,2,3,4', [1., 2., 3., 4.], count=4, sep=',')
- self._check_from('1,2,3,4', [1., 2., 3.], count=3, sep=',')
- self._check_from('1,2,3,4', [1., 2., 3., 4.], count=-1, sep=',')
+ self._check_from(b'1,2,3,4', [1., 2., 3., 4.], count=4, sep=',')
+ self._check_from(b'1,2,3,4', [1., 2., 3.], count=3, sep=',')
+ self._check_from(b'1,2,3,4', [1., 2., 3., 4.], count=-1, sep=',')
def test_string_with_ws(self):
- self._check_from('1 2 3 4 ', [1, 2, 3, 4], dtype=int, sep=' ')
+ self._check_from(b'1 2 3 4 ', [1, 2, 3, 4], dtype=int, sep=' ')
def test_counted_string_with_ws(self):
- self._check_from('1 2 3 4 ', [1, 2, 3], count=3, dtype=int,
+ self._check_from(b'1 2 3 4 ', [1, 2, 3], count=3, dtype=int,
sep=' ')
def test_ascii(self):
- self._check_from('1 , 2 , 3 , 4', [1., 2., 3., 4.], sep=',')
- self._check_from('1,2,3,4', [1., 2., 3., 4.], dtype=float, sep=',')
+ self._check_from(b'1 , 2 , 3 , 4', [1., 2., 3., 4.], sep=',')
+ self._check_from(b'1,2,3,4', [1., 2., 3., 4.], dtype=float, sep=',')
def test_malformed(self):
- self._check_from('1.234 1,234', [1.234, 1.], sep=' ')
+ self._check_from(b'1.234 1,234', [1.234, 1.], sep=' ')
def test_long_sep(self):
- self._check_from('1_x_3_x_4_x_5', [1, 3, 4, 5], sep='_x_')
+ self._check_from(b'1_x_3_x_4_x_5', [1, 3, 4, 5], sep='_x_')
def test_dtype(self):
v = np.array([1, 2, 3, 4], dtype=np.int_)
- self._check_from('1,2,3,4', v, sep=',', dtype=np.int_)
+ self._check_from(b'1,2,3,4', v, sep=',', dtype=np.int_)
def test_dtype_bool(self):
# can't use _check_from because fromstring can't handle True/False
v = np.array([True, False, True, False], dtype=np.bool_)
- s = '1,0,-2.3,0'
+ s = b'1,0,-2.3,0'
f = open(self.filename, 'wb')
- f.write(asbytes(s))
+ f.write(s)
f.close()
y = np.fromfile(self.filename, sep=',', dtype=np.bool_)
assert_(y.dtype == '?')
@@ -4152,7 +4152,7 @@ class TestFromBuffer(object):
yield self.tst_basic, buf, x.flat, {'dtype':dt}
def test_empty(self):
- yield self.tst_basic, asbytes(''), np.array([]), {}
+ yield self.tst_basic, b'', np.array([]), {}
class TestFlat(TestCase):
@@ -4286,17 +4286,17 @@ class TestRecord(TestCase):
def test_bytes_fields(self):
# Bytes are not allowed in field names and not recognized in titles
# on Py3
- assert_raises(TypeError, np.dtype, [(asbytes('a'), int)])
- assert_raises(TypeError, np.dtype, [(('b', asbytes('a')), int)])
+ assert_raises(TypeError, np.dtype, [(b'a', int)])
+ assert_raises(TypeError, np.dtype, [(('b', b'a'), int)])
- dt = np.dtype([((asbytes('a'), 'b'), int)])
- assert_raises(ValueError, dt.__getitem__, asbytes('a'))
+ dt = np.dtype([((b'a', 'b'), int)])
+ assert_raises(ValueError, dt.__getitem__, b'a')
x = np.array([(1,), (2,), (3,)], dtype=dt)
- assert_raises(IndexError, x.__getitem__, asbytes('a'))
+ assert_raises(IndexError, x.__getitem__, b'a')
y = x[0]
- assert_raises(IndexError, y.__getitem__, asbytes('a'))
+ assert_raises(IndexError, y.__getitem__, b'a')
def test_multiple_field_name_unicode(self):
def test_assign_unicode():
@@ -4336,10 +4336,10 @@ class TestRecord(TestCase):
if is_py3:
funcs = (str,)
# byte string indexing fails gracefully
- assert_raises(IndexError, a.__setitem__, asbytes('f1'), 1)
- assert_raises(IndexError, a.__getitem__, asbytes('f1'))
- assert_raises(IndexError, a['f1'].__setitem__, asbytes('sf1'), 1)
- assert_raises(IndexError, a['f1'].__getitem__, asbytes('sf1'))
+ assert_raises(IndexError, a.__setitem__, b'f1', 1)
+ assert_raises(IndexError, a.__getitem__, b'f1')
+ assert_raises(IndexError, a['f1'].__setitem__, b'sf1', 1)
+ assert_raises(IndexError, a['f1'].__getitem__, b'sf1')
else:
funcs = (str, unicode)
for func in funcs:
@@ -5960,7 +5960,7 @@ class TestNewBufferProtocol(object):
]
x = np.array(
[(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- asbytes('aaaa'), 'bbbb', asbytes('xxx'), True, 1.0)],
+ b'aaaa', 'bbbb', b'xxx', True, 1.0)],
dtype=dt)
self._check_roundtrip(x)
@@ -6097,7 +6097,7 @@ class TestNewBufferProtocol(object):
]
x = np.array(
[(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- asbytes('aaaa'), 'bbbb', asbytes(' '), True, 1.0)],
+ b'aaaa', 'bbbb', b' ', True, 1.0)],
dtype=dt)
y = memoryview(x)
assert_equal(y.shape, (1,))
diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py
index 1863f36f7..5ff4468e9 100644
--- a/numpy/core/tests/test_nditer.py
+++ b/numpy/core/tests/test_nditer.py
@@ -5,7 +5,7 @@ import warnings
import numpy as np
from numpy import array, arange, nditer, all
-from numpy.compat import asbytes, sixu
+from numpy.compat import sixu
from numpy.core.multiarray_tests import test_nditer_too_large
from numpy.testing import (
run_module_suite, assert_, assert_equal, assert_array_equal,
@@ -2118,7 +2118,7 @@ def test_iter_buffering_string():
assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
op_dtypes='S2')
i = nditer(a, ['buffered'], ['readonly'], op_dtypes='S6')
- assert_equal(i[0], asbytes('abc'))
+ assert_equal(i[0], b'abc')
assert_equal(i[0].dtype, np.dtype('S6'))
a = np.array(['abc', 'a', 'abcd'], dtype=np.unicode)
diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py
index a7bbe0192..572e0dbaa 100644
--- a/numpy/core/tests/test_numerictypes.py
+++ b/numpy/core/tests/test_numerictypes.py
@@ -3,7 +3,7 @@ from __future__ import division, absolute_import, print_function
import sys
import numpy as np
-from numpy.compat import asbytes, asunicode
+from numpy.compat import asunicode
from numpy.testing import (
TestCase, run_module_suite, assert_, assert_equal
)
@@ -63,8 +63,8 @@ NbufferT = [
# x Info color info y z
# value y2 Info2 name z2 Name Value
# name value y3 z3
- ([3, 2], (6j, 6., (asbytes('nn'), [6j, 4j], [6., 4.], [1, 2]), asbytes('NN'), True), asbytes('cc'), (asunicode('NN'), 6j), [[6., 4.], [6., 4.]], 8),
- ([4, 3], (7j, 7., (asbytes('oo'), [7j, 5j], [7., 5.], [2, 1]), asbytes('OO'), False), asbytes('dd'), (asunicode('OO'), 7j), [[7., 5.], [7., 5.]], 9),
+ ([3, 2], (6j, 6., (b'nn', [6j, 4j], [6., 4.], [1, 2]), b'NN', True), b'cc', (asunicode('NN'), 6j), [[6., 4.], [6., 4.]], 8),
+ ([4, 3], (7j, 7., (b'oo', [7j, 5j], [7., 5.], [2, 1]), b'OO', False), b'dd', (asunicode('OO'), 7j), [[7., 5.], [7., 5.]], 9),
]
diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py
index 74a3be533..6f1ed37d1 100644
--- a/numpy/core/tests/test_records.py
+++ b/numpy/core/tests/test_records.py
@@ -7,7 +7,6 @@ import warnings
from os import path
import numpy as np
-from numpy.compat import asbytes
from numpy.testing import (
TestCase, run_module_suite, assert_, assert_equal, assert_array_equal,
assert_array_almost_equal, assert_raises, assert_warns
@@ -55,18 +54,18 @@ class TestFromrecords(TestCase):
assert_equal(r1, r2)
def test_method_array(self):
- r = np.rec.array(asbytes('abcdefg') * 100, formats='i2,a3,i4', shape=3, byteorder='big')
- assert_equal(r[1].item(), (25444, asbytes('efg'), 1633837924))
+ r = np.rec.array(b'abcdefg' * 100, formats='i2,a3,i4', shape=3, byteorder='big')
+ assert_equal(r[1].item(), (25444, b'efg', 1633837924))
def test_method_array2(self):
r = np.rec.array([(1, 11, 'a'), (2, 22, 'b'), (3, 33, 'c'), (4, 44, 'd'), (5, 55, 'ex'),
(6, 66, 'f'), (7, 77, 'g')], formats='u1,f4,a1')
- assert_equal(r[1].item(), (2, 22.0, asbytes('b')))
+ assert_equal(r[1].item(), (2, 22.0, b'b'))
def test_recarray_slices(self):
r = np.rec.array([(1, 11, 'a'), (2, 22, 'b'), (3, 33, 'c'), (4, 44, 'd'), (5, 55, 'ex'),
(6, 66, 'f'), (7, 77, 'g')], formats='u1,f4,a1')
- assert_equal(r[1::2][1].item(), (4, 44.0, asbytes('d')))
+ assert_equal(r[1::2][1].item(), (4, 44.0, b'd'))
def test_recarray_fromarrays(self):
x1 = np.array([1, 2, 3, 4])
@@ -279,10 +278,10 @@ class TestFromrecords(TestCase):
assert_equal(a[0].bar['A'], 1)
assert_equal(a[0]['bar'].A, 1)
assert_equal(a[0]['bar']['A'], 1)
- assert_equal(a[0].qux.D, asbytes('fgehi'))
- assert_equal(a[0].qux['D'], asbytes('fgehi'))
- assert_equal(a[0]['qux'].D, asbytes('fgehi'))
- assert_equal(a[0]['qux']['D'], asbytes('fgehi'))
+ assert_equal(a[0].qux.D, b'fgehi')
+ assert_equal(a[0].qux['D'], b'fgehi')
+ assert_equal(a[0]['qux'].D, b'fgehi')
+ assert_equal(a[0]['qux']['D'], b'fgehi')
def test_zero_width_strings(self):
# Test for #6430, based on the test case from #1901
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index de84f98b3..d2b568875 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -366,9 +366,9 @@ class TestRegression(TestCase):
def test_chararray_rstrip(self, level=rlevel):
# Ticket #222
x = np.chararray((1,), 5)
- x[0] = asbytes('a ')
+ x[0] = b'a '
x = x.rstrip()
- assert_equal(x[0], asbytes('a'))
+ assert_equal(x[0], b'a')
def test_object_array_shape(self, level=rlevel):
# Ticket #239
@@ -415,23 +415,23 @@ class TestRegression(TestCase):
test_data = [
# (original, py2_pickle)
(np.unicode_('\u6f2c'),
- asbytes("cnumpy.core.multiarray\nscalar\np0\n(cnumpy\ndtype\np1\n"
- "(S'U1'\np2\nI0\nI1\ntp3\nRp4\n(I3\nS'<'\np5\nNNNI4\nI4\n"
- "I0\ntp6\nbS',o\\x00\\x00'\np7\ntp8\nRp9\n.")),
+ b"cnumpy.core.multiarray\nscalar\np0\n(cnumpy\ndtype\np1\n"
+ b"(S'U1'\np2\nI0\nI1\ntp3\nRp4\n(I3\nS'<'\np5\nNNNI4\nI4\n"
+ b"I0\ntp6\nbS',o\\x00\\x00'\np7\ntp8\nRp9\n."),
(np.array([9e123], dtype=np.float64),
- asbytes("cnumpy.core.multiarray\n_reconstruct\np0\n(cnumpy\nndarray\n"
- "p1\n(I0\ntp2\nS'b'\np3\ntp4\nRp5\n(I1\n(I1\ntp6\ncnumpy\ndtype\n"
- "p7\n(S'f8'\np8\nI0\nI1\ntp9\nRp10\n(I3\nS'<'\np11\nNNNI-1\nI-1\n"
- "I0\ntp12\nbI00\nS'O\\x81\\xb7Z\\xaa:\\xabY'\np13\ntp14\nb.")),
+ b"cnumpy.core.multiarray\n_reconstruct\np0\n(cnumpy\nndarray\n"
+ b"p1\n(I0\ntp2\nS'b'\np3\ntp4\nRp5\n(I1\n(I1\ntp6\ncnumpy\ndtype\n"
+ b"p7\n(S'f8'\np8\nI0\nI1\ntp9\nRp10\n(I3\nS'<'\np11\nNNNI-1\nI-1\n"
+ b"I0\ntp12\nbI00\nS'O\\x81\\xb7Z\\xaa:\\xabY'\np13\ntp14\nb."),
(np.array([(9e123,)], dtype=[('name', float)]),
- asbytes("cnumpy.core.multiarray\n_reconstruct\np0\n(cnumpy\nndarray\np1\n"
- "(I0\ntp2\nS'b'\np3\ntp4\nRp5\n(I1\n(I1\ntp6\ncnumpy\ndtype\np7\n"
- "(S'V8'\np8\nI0\nI1\ntp9\nRp10\n(I3\nS'|'\np11\nN(S'name'\np12\ntp13\n"
- "(dp14\ng12\n(g7\n(S'f8'\np15\nI0\nI1\ntp16\nRp17\n(I3\nS'<'\np18\nNNNI-1\n"
- "I-1\nI0\ntp19\nbI0\ntp20\nsI8\nI1\nI0\ntp21\n"
- "bI00\nS'O\\x81\\xb7Z\\xaa:\\xabY'\np22\ntp23\nb.")),
+ b"cnumpy.core.multiarray\n_reconstruct\np0\n(cnumpy\nndarray\np1\n"
+ b"(I0\ntp2\nS'b'\np3\ntp4\nRp5\n(I1\n(I1\ntp6\ncnumpy\ndtype\np7\n"
+ b"(S'V8'\np8\nI0\nI1\ntp9\nRp10\n(I3\nS'|'\np11\nN(S'name'\np12\ntp13\n"
+ b"(dp14\ng12\n(g7\n(S'f8'\np15\nI0\nI1\ntp16\nRp17\n(I3\nS'<'\np18\nNNNI-1\n"
+ b"I-1\nI0\ntp19\nbI0\ntp20\nsI8\nI1\nI0\ntp21\n"
+ b"bI00\nS'O\\x81\\xb7Z\\xaa:\\xabY'\np22\ntp23\nb."),
]
if sys.version_info[:2] >= (3, 4):
@@ -577,7 +577,7 @@ class TestRegression(TestCase):
def test_numeric_carray_compare(self, level=rlevel):
# Ticket #341
- assert_equal(np.array(['X'], 'c'), asbytes('X'))
+ assert_equal(np.array(['X'], 'c'), b'X')
def test_string_array_size(self, level=rlevel):
# Ticket #342
@@ -691,8 +691,8 @@ class TestRegression(TestCase):
def test_junk_in_string_fields_of_recarray(self, level=rlevel):
# Ticket #483
- r = np.array([[asbytes('abc')]], dtype=[('var1', '|S20')])
- assert_(asbytes(r['var1'][0][0]) == asbytes('abc'))
+ r = np.array([[b'abc']], dtype=[('var1', '|S20')])
+ assert_(asbytes(r['var1'][0][0]) == b'abc')
def test_take_output(self, level=rlevel):
# Ensure that 'take' honours output parameter.
@@ -1183,7 +1183,7 @@ class TestRegression(TestCase):
for i in range(1, 9):
msg = 'unicode offset: %d chars' % i
t = np.dtype([('a', 'S%d' % i), ('b', 'U2')])
- x = np.array([(asbytes('a'), sixu('b'))], dtype=t)
+ x = np.array([(b'a', sixu('b'))], dtype=t)
if sys.version_info[0] >= 3:
assert_equal(str(x), "[(b'a', 'b')]", err_msg=msg)
else:
@@ -1499,7 +1499,7 @@ class TestRegression(TestCase):
def test_fromstring_crash(self):
# Ticket #1345: the following should not cause a crash
- np.fromstring(asbytes('aa, aa, 1.0'), sep=',')
+ np.fromstring(b'aa, aa, 1.0', sep=',')
def test_ticket_1539(self):
dtypes = [x for x in np.typeDict.values()
@@ -1593,7 +1593,7 @@ class TestRegression(TestCase):
f.seek(40)
data = f.read(3)
- assert_equal(data, asbytes("\x01\x02\x03"))
+ assert_equal(data, b"\x01\x02\x03")
f.seek(80)
f.read(4)
@@ -1750,8 +1750,8 @@ class TestRegression(TestCase):
def test_setting_rank0_string(self):
"Ticket #1736"
- s1 = asbytes("hello1")
- s2 = asbytes("hello2")
+ s1 = b"hello1"
+ s2 = b"hello2"
a = np.zeros((), dtype="S10")
a[()] = s1
assert_equal(a, np.array(s1))
@@ -1766,9 +1766,9 @@ class TestRegression(TestCase):
def test_string_astype(self):
"Ticket #1748"
- s1 = asbytes('black')
- s2 = asbytes('white')
- s3 = asbytes('other')
+ s1 = b'black'
+ s2 = b'white'
+ s3 = b'other'
a = np.array([[s1], [s2], [s3]])
assert_equal(a.dtype, np.dtype('S5'))
b = a.astype(np.dtype('S0'))
@@ -1776,7 +1776,7 @@ class TestRegression(TestCase):
def test_ticket_1756(self):
# Ticket #1756
- s = asbytes('0123456789abcdef')
+ s = b'0123456789abcdef'
a = np.array([s]*5)
for i in range(1, 17):
a1 = np.array(a, "|S%d" % i)
@@ -1843,10 +1843,10 @@ class TestRegression(TestCase):
# encoding='latin1' work correctly.
# Python2 output for pickle.dumps(numpy.array([129], dtype='b'))
- data = asbytes("cnumpy.core.multiarray\n_reconstruct\np0\n(cnumpy\nndarray\np1\n(I0\n"
- "tp2\nS'b'\np3\ntp4\nRp5\n(I1\n(I1\ntp6\ncnumpy\ndtype\np7\n(S'i1'\np8\n"
- "I0\nI1\ntp9\nRp10\n(I3\nS'|'\np11\nNNNI-1\nI-1\nI0\ntp12\nbI00\nS'\\x81'\n"
- "p13\ntp14\nb.")
+ data = (b"cnumpy.core.multiarray\n_reconstruct\np0\n(cnumpy\nndarray\np1\n(I0\n"
+ b"tp2\nS'b'\np3\ntp4\nRp5\n(I1\n(I1\ntp6\ncnumpy\ndtype\np7\n(S'i1'\np8\n"
+ b"I0\nI1\ntp9\nRp10\n(I3\nS'|'\np11\nNNNI-1\nI-1\nI0\ntp12\nbI00\nS'\\x81'\n"
+ b"p13\ntp14\nb.")
if sys.version_info[0] >= 3:
# This should work:
result = pickle.loads(data, encoding='latin1')
@@ -1862,21 +1862,21 @@ class TestRegression(TestCase):
datas = [
# (original, python2_pickle, koi8r_validity)
(np.unicode_('\u6bd2'),
- asbytes("cnumpy.core.multiarray\nscalar\np0\n(cnumpy\ndtype\np1\n"
- "(S'U1'\np2\nI0\nI1\ntp3\nRp4\n(I3\nS'<'\np5\nNNNI4\nI4\nI0\n"
- "tp6\nbS'\\xd2k\\x00\\x00'\np7\ntp8\nRp9\n."),
+ (b"cnumpy.core.multiarray\nscalar\np0\n(cnumpy\ndtype\np1\n"
+ b"(S'U1'\np2\nI0\nI1\ntp3\nRp4\n(I3\nS'<'\np5\nNNNI4\nI4\nI0\n"
+ b"tp6\nbS'\\xd2k\\x00\\x00'\np7\ntp8\nRp9\n."),
'invalid'),
(np.float64(9e123),
- asbytes("cnumpy.core.multiarray\nscalar\np0\n(cnumpy\ndtype\np1\n(S'f8'\n"
- "p2\nI0\nI1\ntp3\nRp4\n(I3\nS'<'\np5\nNNNI-1\nI-1\nI0\ntp6\n"
- "bS'O\\x81\\xb7Z\\xaa:\\xabY'\np7\ntp8\nRp9\n."),
+ (b"cnumpy.core.multiarray\nscalar\np0\n(cnumpy\ndtype\np1\n(S'f8'\n"
+ b"p2\nI0\nI1\ntp3\nRp4\n(I3\nS'<'\np5\nNNNI-1\nI-1\nI0\ntp6\n"
+ b"bS'O\\x81\\xb7Z\\xaa:\\xabY'\np7\ntp8\nRp9\n."),
'invalid'),
- (np.bytes_(asbytes('\x9c')), # different 8-bit code point in KOI8-R vs latin1
- asbytes("cnumpy.core.multiarray\nscalar\np0\n(cnumpy\ndtype\np1\n(S'S1'\np2\n"
- "I0\nI1\ntp3\nRp4\n(I3\nS'|'\np5\nNNNI1\nI1\nI0\ntp6\nbS'\\x9c'\np7\n"
- "tp8\nRp9\n."),
+ (np.bytes_(b'\x9c'), # different 8-bit code point in KOI8-R vs latin1
+ (b"cnumpy.core.multiarray\nscalar\np0\n(cnumpy\ndtype\np1\n(S'S1'\np2\n"
+ b"I0\nI1\ntp3\nRp4\n(I3\nS'|'\np5\nNNNI1\nI1\nI0\ntp6\nbS'\\x9c'\np7\n"
+ b"tp8\nRp9\n."),
'different'),
]
if sys.version_info[0] >= 3:
diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py
index 8a5e7f603..26e15539e 100644
--- a/numpy/core/tests/test_ufunc.py
+++ b/numpy/core/tests/test_ufunc.py
@@ -3,7 +3,6 @@ from __future__ import division, absolute_import, print_function
import numpy as np
import numpy.core.umath_tests as umt
import numpy.core.operand_flag_tests as opflag_tests
-from numpy.compat import asbytes
from numpy.core.test_rational import rational, test_add, test_add_rationals
from numpy.testing import (
TestCase, run_module_suite, assert_, assert_equal, assert_raises,
@@ -45,8 +44,8 @@ class TestUfunc(TestCase):
def test_pickle_withstring(self):
import pickle
- astring = asbytes("cnumpy.core\n_ufunc_reconstruct\np0\n"
- "(S'numpy.core.umath'\np1\nS'cos'\np2\ntp3\nRp4\n.")
+ astring = (b"cnumpy.core\n_ufunc_reconstruct\np0\n"
+ b"(S'numpy.core.umath'\np1\nS'cos'\np2\ntp3\nRp4\n.")
assert_(pickle.loads(astring) is np.cos)
def test_reduceat_shifting_sum(self):
diff --git a/numpy/core/tests/test_unicode.py b/numpy/core/tests/test_unicode.py
index f2c501235..a28d8dafa 100644
--- a/numpy/core/tests/test_unicode.py
+++ b/numpy/core/tests/test_unicode.py
@@ -3,7 +3,7 @@ from __future__ import division, absolute_import, print_function
import sys
import numpy as np
-from numpy.compat import asbytes, unicode, sixu
+from numpy.compat import unicode, sixu
from numpy.testing import (
TestCase, run_module_suite, assert_, assert_equal, assert_array_equal)
@@ -80,7 +80,7 @@ class create_zeros(object):
# Small check that data in array element is ok
self.assertTrue(ua_scalar == sixu(''))
# Encode to ascii and double check
- self.assertTrue(ua_scalar.encode('ascii') == asbytes(''))
+ self.assertTrue(ua_scalar.encode('ascii') == b'')
# Check buffer lengths for scalars
if ucs4:
self.assertTrue(buffer_length(ua_scalar) == 0)