summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Taves <mwtoews@gmail.com>2022-10-27 06:02:37 +1300
committerGitHub <noreply@github.com>2022-10-26 10:02:37 -0700
commit13d55a3c2f016a58a6e9d6b8086f338e07c7478f (patch)
treea792928b2b4f959bdd685fba9dcf6ef7d049f145
parent12c2b7dd62fc0c14b81c8892ed5f4f59cc94d09c (diff)
downloadnumpy-13d55a3c2f016a58a6e9d6b8086f338e07c7478f.tar.gz
MAINT: remove u-prefix for former Unicode strings (#22479)
-rw-r--r--benchmarks/benchmarks/bench_io.py32
-rw-r--r--doc/neps/conf.py19
-rw-r--r--numpy/core/tests/test_api.py12
-rw-r--r--numpy/core/tests/test_arrayprint.py4
-rw-r--r--numpy/core/tests/test_defchararray.py55
-rw-r--r--numpy/core/tests/test_dtype.py2
-rw-r--r--numpy/core/tests/test_einsum.py5
-rw-r--r--numpy/core/tests/test_multiarray.py31
-rw-r--r--numpy/core/tests/test_nditer.py2
-rw-r--r--numpy/core/tests/test_numerictypes.py6
-rw-r--r--numpy/core/tests/test_overrides.py2
-rw-r--r--numpy/core/tests/test_regression.py26
-rw-r--r--numpy/core/tests/test_scalarinherit.py6
-rw-r--r--numpy/core/tests/test_ufunc.py2
-rw-r--r--numpy/core/tests/test_unicode.py7
-rw-r--r--numpy/lib/tests/test_arraypad.py2
-rw-r--r--numpy/lib/tests/test_format.py4
-rw-r--r--numpy/lib/tests/test_io.py28
-rw-r--r--numpy/ma/core.py2
-rw-r--r--numpy/ma/tests/test_core.py6
-rw-r--r--numpy/ma/tests/test_regression.py2
21 files changed, 129 insertions, 126 deletions
diff --git a/benchmarks/benchmarks/bench_io.py b/benchmarks/benchmarks/bench_io.py
index d5ce9a271..357adbb87 100644
--- a/benchmarks/benchmarks/bench_io.py
+++ b/benchmarks/benchmarks/bench_io.py
@@ -75,12 +75,12 @@ class LoadtxtCSVComments(Benchmark):
param_names = ['num_lines']
def setup(self, num_lines):
- data = [u'1,2,3 # comment'] * num_lines
+ data = ['1,2,3 # comment'] * num_lines
# unfortunately, timeit will only run setup()
# between repeat events, but not for iterations
# within repeats, so the StringIO object
# will have to be rewinded in the benchmark proper
- self.data_comments = StringIO(u'\n'.join(data))
+ self.data_comments = StringIO('\n'.join(data))
def time_comment_loadtxt_csv(self, num_lines):
# benchmark handling of lines with comments
@@ -93,7 +93,7 @@ class LoadtxtCSVComments(Benchmark):
# confounding timing result somewhat) for every
# call to timing test proper
np.loadtxt(self.data_comments,
- delimiter=u',')
+ delimiter=',')
self.data_comments.seek(0)
class LoadtxtCSVdtypes(Benchmark):
@@ -106,8 +106,8 @@ class LoadtxtCSVdtypes(Benchmark):
param_names = ['dtype', 'num_lines']
def setup(self, dtype, num_lines):
- data = [u'5, 7, 888'] * num_lines
- self.csv_data = StringIO(u'\n'.join(data))
+ data = ['5, 7, 888'] * num_lines
+ self.csv_data = StringIO('\n'.join(data))
def time_loadtxt_dtypes_csv(self, dtype, num_lines):
# benchmark loading arrays of various dtypes
@@ -117,7 +117,7 @@ class LoadtxtCSVdtypes(Benchmark):
# rewind of StringIO object
np.loadtxt(self.csv_data,
- delimiter=u',',
+ delimiter=',',
dtype=dtype)
self.csv_data.seek(0)
@@ -127,15 +127,15 @@ class LoadtxtCSVStructured(Benchmark):
def setup(self):
num_lines = 50000
- data = [u"M, 21, 72, X, 155"] * num_lines
- self.csv_data = StringIO(u'\n'.join(data))
+ data = ["M, 21, 72, X, 155"] * num_lines
+ self.csv_data = StringIO('\n'.join(data))
def time_loadtxt_csv_struct_dtype(self):
# obligate rewind of StringIO object
# between iterations of a repeat:
np.loadtxt(self.csv_data,
- delimiter=u',',
+ delimiter=',',
dtype=[('category_1', 'S1'),
('category_2', 'i4'),
('category_3', 'f8'),
@@ -174,10 +174,10 @@ class LoadtxtReadUint64Integers(Benchmark):
def setup(self, size):
arr = np.arange(size).astype('uint64') + 2**63
- self.data1 = StringIO(u'\n'.join(arr.astype(str).tolist()))
+ self.data1 = StringIO('\n'.join(arr.astype(str).tolist()))
arr = arr.astype(object)
arr[500] = -1
- self.data2 = StringIO(u'\n'.join(arr.astype(str).tolist()))
+ self.data2 = StringIO('\n'.join(arr.astype(str).tolist()))
def time_read_uint64(self, size):
# mandatory rewind of StringIO object
@@ -200,14 +200,14 @@ class LoadtxtUseColsCSV(Benchmark):
def setup(self, usecols):
num_lines = 5000
- data = [u'0, 1, 2, 3, 4, 5, 6, 7, 8, 9'] * num_lines
- self.csv_data = StringIO(u'\n'.join(data))
+ data = ['0, 1, 2, 3, 4, 5, 6, 7, 8, 9'] * num_lines
+ self.csv_data = StringIO('\n'.join(data))
def time_loadtxt_usecols_csv(self, usecols):
# must rewind StringIO because of state
# dependence of file reading
np.loadtxt(self.csv_data,
- delimiter=u',',
+ delimiter=',',
usecols=usecols)
self.csv_data.seek(0)
@@ -225,7 +225,7 @@ class LoadtxtCSVDateTime(Benchmark):
dates = np.arange('today', 20, dtype=np.datetime64)
np.random.seed(123)
values = np.random.rand(20)
- date_line = u''
+ date_line = ''
for date, value in zip(dates, values):
date_line += (str(date) + ',' + str(value) + '\n')
@@ -238,7 +238,7 @@ class LoadtxtCSVDateTime(Benchmark):
# rewind StringIO object -- the timing iterations
# are state-dependent
X = np.loadtxt(self.csv_data,
- delimiter=u',',
+ delimiter=',',
dtype=([('dates', 'M8[us]'),
('values', 'float64')]))
self.csv_data.seek(0)
diff --git a/doc/neps/conf.py b/doc/neps/conf.py
index a0ab286bd..10644a190 100644
--- a/doc/neps/conf.py
+++ b/doc/neps/conf.py
@@ -47,18 +47,19 @@ source_suffix = '.rst'
master_doc = 'content'
# General information about the project.
-project = u'NumPy Enhancement Proposals'
-copyright = u'2017-2018, NumPy Developers'
-author = u'NumPy Developers'
+project = 'NumPy Enhancement Proposals'
+copyright = '2017-2018, NumPy Developers'
+author = 'NumPy Developers'
+title = 'NumPy Enhancement Proposals Documentation'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
-version = u''
+version = ''
# The full version, including alpha/beta/rc tags.
-release = u''
+release = ''
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@@ -147,8 +148,8 @@ latex_elements = {
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
- (master_doc, 'NumPyEnhancementProposals.tex', u'NumPy Enhancement Proposals Documentation',
- u'NumPy Developers', 'manual'),
+ (master_doc, 'NumPyEnhancementProposals.tex', title,
+ 'NumPy Developers', 'manual'),
]
@@ -157,7 +158,7 @@ latex_documents = [
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
- (master_doc, 'numpyenhancementproposals', u'NumPy Enhancement Proposals Documentation',
+ (master_doc, 'numpyenhancementproposals', title,
[author], 1)
]
@@ -168,7 +169,7 @@ man_pages = [
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
- (master_doc, 'NumPyEnhancementProposals', u'NumPy Enhancement Proposals Documentation',
+ (master_doc, 'NumPyEnhancementProposals', title,
author, 'NumPyEnhancementProposals', 'One line description of project.',
'Miscellaneous'),
]
diff --git a/numpy/core/tests/test_api.py b/numpy/core/tests/test_api.py
index 29e4a511d..5006e77f2 100644
--- a/numpy/core/tests/test_api.py
+++ b/numpy/core/tests/test_api.py
@@ -234,7 +234,7 @@ def test_array_astype():
b = a.astype('S')
assert_equal(a, b)
assert_equal(b.dtype, np.dtype('S100'))
- a = np.array([u'a'*100], dtype='O')
+ a = np.array(['a'*100], dtype='O')
b = a.astype('U')
assert_equal(a, b)
assert_equal(b.dtype, np.dtype('U100'))
@@ -244,7 +244,7 @@ def test_array_astype():
b = a.astype('S')
assert_equal(a, b)
assert_equal(b.dtype, np.dtype('S10'))
- a = np.array([u'a'*10], dtype='O')
+ a = np.array(['a'*10], dtype='O')
b = a.astype('U')
assert_equal(a, b)
assert_equal(b.dtype, np.dtype('U10'))
@@ -252,19 +252,19 @@ def test_array_astype():
a = np.array(123456789012345678901234567890, dtype='O').astype('S')
assert_array_equal(a, np.array(b'1234567890' * 3, dtype='S30'))
a = np.array(123456789012345678901234567890, dtype='O').astype('U')
- assert_array_equal(a, np.array(u'1234567890' * 3, dtype='U30'))
+ assert_array_equal(a, np.array('1234567890' * 3, dtype='U30'))
a = np.array([123456789012345678901234567890], dtype='O').astype('S')
assert_array_equal(a, np.array(b'1234567890' * 3, dtype='S30'))
a = np.array([123456789012345678901234567890], dtype='O').astype('U')
- assert_array_equal(a, np.array(u'1234567890' * 3, dtype='U30'))
+ assert_array_equal(a, np.array('1234567890' * 3, dtype='U30'))
a = np.array(123456789012345678901234567890, dtype='S')
assert_array_equal(a, np.array(b'1234567890' * 3, dtype='S30'))
a = np.array(123456789012345678901234567890, dtype='U')
- assert_array_equal(a, np.array(u'1234567890' * 3, dtype='U30'))
+ assert_array_equal(a, np.array('1234567890' * 3, dtype='U30'))
- a = np.array(u'a\u0140', dtype='U')
+ a = np.array('a\u0140', dtype='U')
b = np.ndarray(buffer=a, dtype='uint32', shape=2)
assert_(b.size == 2)
diff --git a/numpy/core/tests/test_arrayprint.py b/numpy/core/tests/test_arrayprint.py
index 25826d8ed..4969cc6ae 100644
--- a/numpy/core/tests/test_arrayprint.py
+++ b/numpy/core/tests/test_arrayprint.py
@@ -549,7 +549,7 @@ class TestPrintOptions:
assert_equal(repr(x), "array([0., 1., 2.])")
def test_0d_arrays(self):
- assert_equal(str(np.array(u'café', '<U4')), u'café')
+ assert_equal(str(np.array('café', '<U4')), 'café')
assert_equal(repr(np.array('café', '<U4')),
"array('café', dtype='<U4')")
@@ -931,7 +931,7 @@ class TestPrintOptions:
def test_unicode_object_array():
expected = "array(['é'], dtype=object)"
- x = np.array([u'\xe9'], dtype=object)
+ x = np.array(['\xe9'], dtype=object)
assert_equal(repr(x), expected)
diff --git a/numpy/core/tests/test_defchararray.py b/numpy/core/tests/test_defchararray.py
index 59fc54722..817487c79 100644
--- a/numpy/core/tests/test_defchararray.py
+++ b/numpy/core/tests/test_defchararray.py
@@ -1,4 +1,3 @@
-
import numpy as np
from numpy.core.multiarray import _vec_string
from numpy.testing import (
@@ -19,12 +18,12 @@ class TestBasic:
[b'long', b'0123456789']])
def test_from_object_array_unicode(self):
- A = np.array([['abc', u'Sigma \u03a3'],
+ A = np.array([['abc', 'Sigma \u03a3'],
['long ', '0123456789']], dtype='O')
assert_raises(ValueError, np.char.array, (A,))
B = np.char.array(A, **kw_unicode_true)
assert_equal(B.dtype.itemsize, 10 * np.array('a', 'U').dtype.itemsize)
- assert_array_equal(B, [['abc', u'Sigma \u03a3'],
+ assert_array_equal(B, [['abc', 'Sigma \u03a3'],
['long', '0123456789']])
def test_from_string_array(self):
@@ -45,7 +44,7 @@ class TestBasic:
assert_(C[0, 0] == A[0, 0])
def test_from_unicode_array(self):
- A = np.array([['abc', u'Sigma \u03a3'],
+ A = np.array([['abc', 'Sigma \u03a3'],
['long ', '0123456789']])
assert_equal(A.dtype.type, np.unicode_)
B = np.char.array(A)
@@ -64,7 +63,7 @@ class TestBasic:
def test_unicode_upconvert(self):
A = np.char.array(['abc'])
- B = np.char.array([u'\u03a3'])
+ B = np.char.array(['\u03a3'])
assert_(issubclass((A + B).dtype.type, np.unicode_))
def test_from_string(self):
@@ -74,7 +73,7 @@ class TestBasic:
assert_(issubclass(A.dtype.type, np.string_))
def test_from_unicode(self):
- A = np.char.array(u'\u03a3')
+ A = np.char.array('\u03a3')
assert_equal(len(A), 1)
assert_equal(len(A[0]), 1)
assert_equal(A.itemsize, 4)
@@ -206,9 +205,9 @@ class TestInformation:
self.A = np.array([[' abc ', ''],
['12345', 'MixedCase'],
['123 \t 345 \0 ', 'UPPER']]).view(np.chararray)
- self.B = np.array([[u' \u03a3 ', u''],
- [u'12345', u'MixedCase'],
- [u'123 \t 345 \0 ', u'UPPER']]).view(np.chararray)
+ self.B = np.array([[' \u03a3 ', ''],
+ ['12345', 'MixedCase'],
+ ['123 \t 345 \0 ', 'UPPER']]).view(np.chararray)
def test_len(self):
assert_(issubclass(np.char.str_len(self.A).dtype.type, np.integer))
@@ -313,9 +312,9 @@ class TestMethods:
['12345', 'MixedCase'],
['123 \t 345 \0 ', 'UPPER']],
dtype='S').view(np.chararray)
- self.B = np.array([[u' \u03a3 ', u''],
- [u'12345', u'MixedCase'],
- [u'123 \t 345 \0 ', u'UPPER']]).view(np.chararray)
+ self.B = np.array([[' \u03a3 ', ''],
+ ['12345', 'MixedCase'],
+ ['123 \t 345 \0 ', 'UPPER']]).view(np.chararray)
def test_capitalize(self):
tgt = [[b' abc ', b''],
@@ -324,7 +323,7 @@ class TestMethods:
assert_(issubclass(self.A.capitalize().dtype.type, np.string_))
assert_array_equal(self.A.capitalize(), tgt)
- tgt = [[u' \u03c3 ', ''],
+ tgt = [[' \u03c3 ', ''],
['12345', 'Mixedcase'],
['123 \t 345 \0 ', 'Upper']]
assert_(issubclass(self.B.capitalize().dtype.type, np.unicode_))
@@ -393,9 +392,9 @@ class TestMethods:
assert_(issubclass(self.A.lower().dtype.type, np.string_))
assert_array_equal(self.A.lower(), tgt)
- tgt = [[u' \u03c3 ', u''],
- [u'12345', u'mixedcase'],
- [u'123 \t 345 \0 ', u'upper']]
+ tgt = [[' \u03c3 ', ''],
+ ['12345', 'mixedcase'],
+ ['123 \t 345 \0 ', 'upper']]
assert_(issubclass(self.B.lower().dtype.type, np.unicode_))
assert_array_equal(self.B.lower(), tgt)
@@ -411,7 +410,7 @@ class TestMethods:
[b'23 \t 345 \x00', b'UPPER']]
assert_array_equal(self.A.lstrip([b'1', b'M']), tgt)
- tgt = [[u'\u03a3 ', ''],
+ tgt = [['\u03a3 ', ''],
['12345', 'MixedCase'],
['123 \t 345 \0 ', 'UPPER']]
assert_(issubclass(self.B.lstrip().dtype.type, np.unicode_))
@@ -481,7 +480,7 @@ class TestMethods:
]
assert_array_equal(self.A.rstrip([b'5', b'ER']), tgt)
- tgt = [[u' \u03a3', ''],
+ tgt = [[' \u03a3', ''],
['12345', 'MixedCase'],
['123 \t 345', 'UPPER']]
assert_(issubclass(self.B.rstrip().dtype.type, np.unicode_))
@@ -499,7 +498,7 @@ class TestMethods:
[b'23 \t 345 \x00', b'UPP']]
assert_array_equal(self.A.strip([b'15', b'EReM']), tgt)
- tgt = [[u'\u03a3', ''],
+ tgt = [['\u03a3', ''],
['12345', 'MixedCase'],
['123 \t 345', 'UPPER']]
assert_(issubclass(self.B.strip().dtype.type, np.unicode_))
@@ -527,9 +526,9 @@ class TestMethods:
assert_(issubclass(self.A.swapcase().dtype.type, np.string_))
assert_array_equal(self.A.swapcase(), tgt)
- tgt = [[u' \u03c3 ', u''],
- [u'12345', u'mIXEDcASE'],
- [u'123 \t 345 \0 ', u'upper']]
+ tgt = [[' \u03c3 ', ''],
+ ['12345', 'mIXEDcASE'],
+ ['123 \t 345 \0 ', 'upper']]
assert_(issubclass(self.B.swapcase().dtype.type, np.unicode_))
assert_array_equal(self.B.swapcase(), tgt)
@@ -540,9 +539,9 @@ class TestMethods:
assert_(issubclass(self.A.title().dtype.type, np.string_))
assert_array_equal(self.A.title(), tgt)
- tgt = [[u' \u03a3 ', u''],
- [u'12345', u'Mixedcase'],
- [u'123 \t 345 \0 ', u'Upper']]
+ tgt = [[' \u03a3 ', ''],
+ ['12345', 'Mixedcase'],
+ ['123 \t 345 \0 ', 'Upper']]
assert_(issubclass(self.B.title().dtype.type, np.unicode_))
assert_array_equal(self.B.title(), tgt)
@@ -553,9 +552,9 @@ class TestMethods:
assert_(issubclass(self.A.upper().dtype.type, np.string_))
assert_array_equal(self.A.upper(), tgt)
- tgt = [[u' \u03a3 ', u''],
- [u'12345', u'MIXEDCASE'],
- [u'123 \t 345 \0 ', u'UPPER']]
+ tgt = [[' \u03a3 ', ''],
+ ['12345', 'MIXEDCASE'],
+ ['123 \t 345 \0 ', 'UPPER']]
assert_(issubclass(self.B.upper().dtype.type, np.unicode_))
assert_array_equal(self.B.upper(), tgt)
diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py
index f7819e83b..91f314d05 100644
--- a/numpy/core/tests/test_dtype.py
+++ b/numpy/core/tests/test_dtype.py
@@ -1451,7 +1451,7 @@ def test_dtypes_are_true():
def test_invalid_dtype_string():
# test for gh-10440
assert_raises(TypeError, np.dtype, 'f8,i8,[f8,i8]')
- assert_raises(TypeError, np.dtype, u'Fl\xfcgel')
+ assert_raises(TypeError, np.dtype, 'Fl\xfcgel')
def test_keyword_argument():
diff --git a/numpy/core/tests/test_einsum.py b/numpy/core/tests/test_einsum.py
index 623ebcbe2..7c0e8d97c 100644
--- a/numpy/core/tests/test_einsum.py
+++ b/numpy/core/tests/test_einsum.py
@@ -596,11 +596,10 @@ class TestEinsum:
assert_equal(np.einsum('ij...,j...->i...', a, b, optimize=True), [[[2], [2]]])
# Regression test for issue #10369 (test unicode inputs with Python 2)
- assert_equal(np.einsum(u'ij...,j...->i...', a, b), [[[2], [2]]])
+ assert_equal(np.einsum('ij...,j...->i...', a, b), [[[2], [2]]])
assert_equal(np.einsum('...i,...i', [1, 2, 3], [2, 3, 4]), 20)
- assert_equal(np.einsum(u'...i,...i', [1, 2, 3], [2, 3, 4]), 20)
assert_equal(np.einsum('...i,...i', [1, 2, 3], [2, 3, 4],
- optimize=u'greedy'), 20)
+ optimize='greedy'), 20)
# The iterator had an issue with buffering this reduction
a = np.ones((5, 12, 4, 2, 3), np.int64)
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 5e0336ce3..261050619 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -564,18 +564,18 @@ class TestAssignment:
finally:
set_string_function(None, repr=False)
- a1d = np.array([u'test'])
- a0d = np.array(u'done')
- with inject_str(u'bad'):
+ a1d = np.array(['test'])
+ a0d = np.array('done')
+ with inject_str('bad'):
a1d[0] = a0d # previously this would invoke __str__
- assert_equal(a1d[0], u'done')
+ assert_equal(a1d[0], 'done')
# this would crash for the same reason
- np.array([np.array(u'\xe5\xe4\xf6')])
+ np.array([np.array('\xe5\xe4\xf6')])
def test_stringlike_empty_list(self):
# gh-8902
- u = np.array([u'done'])
+ u = np.array(['done'])
b = np.array([b'done'])
class bad_sequence:
@@ -4404,8 +4404,8 @@ class TestStringCompare:
assert_array_equal(g1 >= g2, [x >= g2 for x in g1])
def test_unicode(self):
- g1 = np.array([u"This", u"is", u"example"])
- g2 = np.array([u"This", u"was", u"example"])
+ g1 = np.array(["This", "is", "example"])
+ g2 = np.array(["This", "was", "example"])
assert_array_equal(g1 == g2, [g1[i] == g2[i] for i in [0, 1, 2]])
assert_array_equal(g1 != g2, [g1[i] != g2[i] for i in [0, 1, 2]])
assert_array_equal(g1 <= g2, [g1[i] <= g2[i] for i in [0, 1, 2]])
@@ -5909,17 +5909,18 @@ class TestRecord:
def test_fromarrays_unicode(self):
# A single name string provided to fromarrays() is allowed to be unicode
# on both Python 2 and 3:
- x = np.core.records.fromarrays([[0], [1]], names=u'a,b', formats=u'i4,i4')
+ x = np.core.records.fromarrays(
+ [[0], [1]], names='a,b', formats='i4,i4')
assert_equal(x['a'][0], 0)
assert_equal(x['b'][0], 1)
def test_unicode_order(self):
# Test that we can sort with order as a unicode field name in both Python 2 and
# 3:
- name = u'b'
+ name = 'b'
x = np.array([1, 3, 2], dtype=[(name, int)])
x.sort(order=name)
- assert_equal(x[u'b'], np.array([1, 2, 3]))
+ assert_equal(x['b'], np.array([1, 2, 3]))
def test_field_names(self):
# Test unicode and 8-bit / byte strings can be used
@@ -5959,8 +5960,8 @@ class TestRecord:
assert_equal(b[['f1', 'f3']][0].tolist(), (2, (1,)))
# non-ascii unicode field indexing is well behaved
- assert_raises(ValueError, a.__setitem__, u'\u03e0', 1)
- assert_raises(ValueError, a.__getitem__, u'\u03e0')
+ assert_raises(ValueError, a.__setitem__, '\u03e0', 1)
+ assert_raises(ValueError, a.__getitem__, '\u03e0')
def test_record_hash(self):
a = np.array([(1, 2), (1, 2)], dtype='i1,i2')
@@ -8653,7 +8654,7 @@ class TestConversion:
# gh-9972
assert_equal(4, int_func(np.array('4')))
assert_equal(5, int_func(np.bytes_(b'5')))
- assert_equal(6, int_func(np.unicode_(u'6')))
+ assert_equal(6, int_func(np.unicode_('6')))
# The delegation of int() to __trunc__ was deprecated in
# Python 3.11.
@@ -9395,7 +9396,7 @@ class TestArrayFinalize:
def test_orderconverter_with_nonASCII_unicode_ordering():
# gh-7475
a = np.arange(5)
- assert_raises(ValueError, a.flatten, order=u'\xe2')
+ assert_raises(ValueError, a.flatten, order='\xe2')
def test_equal_override():
diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py
index f64d18edd..07ff1c415 100644
--- a/numpy/core/tests/test_nditer.py
+++ b/numpy/core/tests/test_nditer.py
@@ -2261,7 +2261,7 @@ def test_iter_buffering_string():
assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
op_dtypes='U2')
i = nditer(a, ['buffered'], ['readonly'], op_dtypes='U6')
- assert_equal(i[0], u'abc')
+ assert_equal(i[0], 'abc')
assert_equal(i[0].dtype, np.dtype('U6'))
def test_iter_buffering_growinner():
diff --git a/numpy/core/tests/test_numerictypes.py b/numpy/core/tests/test_numerictypes.py
index 73ff4764d..31faa835c 100644
--- a/numpy/core/tests/test_numerictypes.py
+++ b/numpy/core/tests/test_numerictypes.py
@@ -60,8 +60,10 @@ NbufferT = [
# x Info color info y z
# value y2 Info2 name z2 Name Value
# name value y3 z3
- ([3, 2], (6j, 6., (b'nn', [6j, 4j], [6., 4.], [1, 2]), b'NN', True), b'cc', (u'NN', 6j), [[6., 4.], [6., 4.]], 8),
- ([4, 3], (7j, 7., (b'oo', [7j, 5j], [7., 5.], [2, 1]), b'OO', False), b'dd', (u'OO', 7j), [[7., 5.], [7., 5.]], 9),
+ ([3, 2], (6j, 6., (b'nn', [6j, 4j], [6., 4.], [1, 2]), b'NN', True),
+ b'cc', ('NN', 6j), [[6., 4.], [6., 4.]], 8),
+ ([4, 3], (7j, 7., (b'oo', [7j, 5j], [7., 5.], [2, 1]), b'OO', False),
+ b'dd', ('OO', 7j), [[7., 5.], [7., 5.]], 9),
]
diff --git a/numpy/core/tests/test_overrides.py b/numpy/core/tests/test_overrides.py
index 84e864afd..4de764a34 100644
--- a/numpy/core/tests/test_overrides.py
+++ b/numpy/core/tests/test_overrides.py
@@ -531,7 +531,7 @@ class TestArrayLike:
('fromiter', *func_args(range(3), dtype=int)),
('fromstring', *func_args('1,2', dtype=int, sep=',')),
('loadtxt', *func_args(lambda: StringIO('0 1\n2 3'))),
- ('genfromtxt', *func_args(lambda: StringIO(u'1,2.1'),
+ ('genfromtxt', *func_args(lambda: StringIO('1,2.1'),
dtype=[('int', 'i8'), ('float', 'f8')],
delimiter=',')),
]
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 2f2d115a4..427e868e8 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -137,7 +137,7 @@ class TestRegression:
def test_unicode_swapping(self):
# Ticket #79
ulen = 1
- ucs_value = u'\U0010FFFF'
+ ucs_value = '\U0010FFFF'
ua = np.array([[[ucs_value*ulen]*2]*3]*4, dtype='U%s' % ulen)
ua.newbyteorder() # Should succeed.
@@ -1211,7 +1211,7 @@ class TestRegression:
for i in range(1, 9):
msg = 'unicode offset: %d chars' % i
t = np.dtype([('a', 'S%d' % i), ('b', 'U2')])
- x = np.array([(b'a', u'b')], dtype=t)
+ x = np.array([(b'a', 'b')], dtype=t)
assert_equal(str(x), "[(b'a', 'b')]", err_msg=msg)
def test_sign_for_complex_nan(self):
@@ -1396,28 +1396,28 @@ class TestRegression:
def test_unicode_to_string_cast(self):
# Ticket #1240.
- a = np.array([[u'abc', u'\u03a3'],
- [u'asdf', u'erw']],
+ a = np.array([['abc', '\u03a3'],
+ ['asdf', 'erw']],
dtype='U')
assert_raises(UnicodeEncodeError, np.array, a, 'S4')
def test_unicode_to_string_cast_error(self):
# gh-15790
- a = np.array([u'\x80'] * 129, dtype='U3')
+ a = np.array(['\x80'] * 129, dtype='U3')
assert_raises(UnicodeEncodeError, np.array, a, 'S')
b = a.reshape(3, 43)[:-1, :-1]
assert_raises(UnicodeEncodeError, np.array, b, 'S')
- def test_mixed_string_unicode_array_creation(self):
- a = np.array(['1234', u'123'])
+ def test_mixed_string_byte_array_creation(self):
+ a = np.array(['1234', b'123'])
assert_(a.itemsize == 16)
- a = np.array([u'123', '1234'])
+ a = np.array([b'123', '1234'])
assert_(a.itemsize == 16)
- a = np.array(['1234', u'123', '12345'])
+ a = np.array(['1234', b'123', '12345'])
assert_(a.itemsize == 20)
- a = np.array([u'123', '1234', u'12345'])
+ a = np.array([b'123', '1234', b'12345'])
assert_(a.itemsize == 20)
- a = np.array([u'123', '1234', u'1234'])
+ a = np.array([b'123', '1234', b'1234'])
assert_(a.itemsize == 16)
def test_misaligned_objects_segfault(self):
@@ -2135,8 +2135,8 @@ class TestRegression:
import numpy as np
a = np.array([['Hello', 'Foob']], dtype='U5', order='F')
arr = np.ndarray(shape=[1, 2, 5], dtype='U1', buffer=a)
- arr2 = np.array([[[u'H', u'e', u'l', u'l', u'o'],
- [u'F', u'o', u'o', u'b', u'']]])
+ arr2 = np.array([[['H', 'e', 'l', 'l', 'o'],
+ ['F', 'o', 'o', 'b', '']]])
assert_array_equal(arr, arr2)
def test_assign_from_sequence_error(self):
diff --git a/numpy/core/tests/test_scalarinherit.py b/numpy/core/tests/test_scalarinherit.py
index 98d7f7cde..f697c3c81 100644
--- a/numpy/core/tests/test_scalarinherit.py
+++ b/numpy/core/tests/test_scalarinherit.py
@@ -61,7 +61,7 @@ class TestCharacter:
np_s = np.string_('abc')
np_u = np.unicode_('abc')
s = b'def'
- u = u'def'
+ u = 'def'
assert_(np_s.__radd__(np_s) is NotImplemented)
assert_(np_s.__radd__(np_u) is NotImplemented)
assert_(np_s.__radd__(s) is NotImplemented)
@@ -71,7 +71,7 @@ class TestCharacter:
assert_(np_u.__radd__(s) is NotImplemented)
assert_(np_u.__radd__(u) is NotImplemented)
assert_(s + np_s == b'defabc')
- assert_(u + np_u == u'defabc')
+ assert_(u + np_u == 'defabc')
class MyStr(str, np.generic):
# would segfault
@@ -93,6 +93,6 @@ class TestCharacter:
np_s = np.string_('abc')
np_u = np.unicode_('abc')
res_s = b'abc' * 5
- res_u = u'abc' * 5
+ res_u = 'abc' * 5
assert_(np_s * 5 == res_s)
assert_(np_u * 5 == res_u)
diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py
index ce30e63db..55767a3ef 100644
--- a/numpy/core/tests/test_ufunc.py
+++ b/numpy/core/tests/test_ufunc.py
@@ -334,7 +334,7 @@ class TestUfunc:
def test_signature3(self):
enabled, num_dims, ixs, flags, sizes = umt.test_signature(
- 2, 1, u"(i1, i12), (J_1)->(i12, i2)")
+ 2, 1, "(i1, i12), (J_1)->(i12, i2)")
assert_equal(enabled, 1)
assert_equal(num_dims, (2, 1, 2))
assert_equal(ixs, (0, 1, 2, 1, 3))
diff --git a/numpy/core/tests/test_unicode.py b/numpy/core/tests/test_unicode.py
index 12de25771..2d7c2818e 100644
--- a/numpy/core/tests/test_unicode.py
+++ b/numpy/core/tests/test_unicode.py
@@ -22,12 +22,13 @@ def buffer_length(arr):
else:
return np.prod(v.shape) * v.itemsize
+
# In both cases below we need to make sure that the byte swapped value (as
# UCS4) is still a valid unicode:
# Value that can be represented in UCS2 interpreters
-ucs2_value = u'\u0900'
+ucs2_value = '\u0900'
# Value that cannot be represented in UCS2 interpreters (but can in UCS4)
-ucs4_value = u'\U00100900'
+ucs4_value = '\U00100900'
def test_string_cast():
@@ -57,7 +58,7 @@ class CreateZeros:
# Check the length of the data buffer
assert_(buffer_length(ua) == nbytes)
# Small check that data in array element is ok
- assert_(ua_scalar == u'')
+ assert_(ua_scalar == '')
# Encode to ascii and double check
assert_(ua_scalar.encode('ascii') == b'')
# Check buffer lengths for scalars
diff --git a/numpy/lib/tests/test_arraypad.py b/numpy/lib/tests/test_arraypad.py
index 64b6a2e18..a59681573 100644
--- a/numpy/lib/tests/test_arraypad.py
+++ b/numpy/lib/tests/test_arraypad.py
@@ -1214,7 +1214,7 @@ def test_legacy_vector_functionality():
def test_unicode_mode():
- a = np.pad([1], 2, mode=u'constant')
+ a = np.pad([1], 2, mode='constant')
b = np.array([0, 0, 1, 0, 0])
assert_array_equal(a, b)
diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py
index 3da59789d..08878a1f9 100644
--- a/numpy/lib/tests/test_format.py
+++ b/numpy/lib/tests/test_format.py
@@ -537,7 +537,7 @@ def test_pickle_python2_python3():
# Python 2 and Python 3 and vice versa
data_dir = os.path.join(os.path.dirname(__file__), 'data')
- expected = np.array([None, range, u'\u512a\u826f',
+ expected = np.array([None, range, '\u512a\u826f',
b'\xe4\xb8\x8d\xe8\x89\xaf'],
dtype=object)
@@ -963,7 +963,7 @@ def test_unicode_field_names(tmpdir):
(1, 2)
], dtype=[
('int', int),
- (u'\N{CJK UNIFIED IDEOGRAPH-6574}\N{CJK UNIFIED IDEOGRAPH-5F62}', int)
+ ('\N{CJK UNIFIED IDEOGRAPH-6574}\N{CJK UNIFIED IDEOGRAPH-5F62}', int)
])
fname = os.path.join(tmpdir, "unicode.npy")
with open(fname, 'wb') as f:
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 0756cc646..b39db72eb 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -560,7 +560,7 @@ class TestSaveTxt:
s.seek(0)
assert_equal(s.read(), utf8 + '\n')
- @pytest.mark.parametrize("fmt", [u"%f", b"%f"])
+ @pytest.mark.parametrize("fmt", ["%f", b"%f"])
@pytest.mark.parametrize("iotype", [StringIO, BytesIO])
def test_unicode_and_bytes_fmt(self, fmt, iotype):
# string type of fmt should not matter, see also gh-4053
@@ -569,7 +569,7 @@ class TestSaveTxt:
np.savetxt(s, a, fmt=fmt)
s.seek(0)
if iotype is StringIO:
- assert_equal(s.read(), u"%f\n" % 1.)
+ assert_equal(s.read(), "%f\n" % 1.)
else:
assert_equal(s.read(), b"%f\n" % 1.)
@@ -763,7 +763,7 @@ class TestLoadTxt(LoadTxtBase):
c.write('# comment\n1,2,3,5\n')
c.seek(0)
x = np.loadtxt(c, dtype=int, delimiter=',',
- comments=u'#')
+ comments='#')
a = np.array([1, 2, 3, 5], int)
assert_array_equal(x, a)
@@ -1514,7 +1514,7 @@ M 33 21.99
with tempdir() as tmpdir:
fpath = os.path.join(tmpdir, "test.csv")
with open(fpath, "wb") as f:
- f.write(u'\N{GREEK PI SYMBOL}'.encode('utf8'))
+ f.write('\N{GREEK PI SYMBOL}'.encode())
# ResourceWarnings are emitted from a destructor, so won't be
# detected by regular propagation to errors.
@@ -2174,9 +2174,9 @@ M 33 21.99
test = np.genfromtxt(TextIO(s),
dtype=None, comments=None, delimiter=',',
encoding='latin1')
- assert_equal(test[1, 0], u"test1")
- assert_equal(test[1, 1], u"testNonethe" + latin1.decode('latin1'))
- assert_equal(test[1, 2], u"test3")
+ assert_equal(test[1, 0], "test1")
+ assert_equal(test[1, 1], "testNonethe" + latin1.decode('latin1'))
+ assert_equal(test[1, 2], "test3")
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings('always', '', np.VisibleDeprecationWarning)
@@ -2230,8 +2230,8 @@ M 33 21.99
def test_utf8_file_nodtype_unicode(self):
# bytes encoding with non-latin1 -> unicode upcast
- utf8 = u'\u03d6'
- latin1 = u'\xf6\xfc\xf6'
+ utf8 = '\u03d6'
+ latin1 = '\xf6\xfc\xf6'
# skip test if cannot encode utf8 test string with preferred
# encoding. The preferred encoding is assumed to be the default
@@ -2246,9 +2246,9 @@ M 33 21.99
with temppath() as path:
with io.open(path, "wt") as f:
- f.write(u"norm1,norm2,norm3\n")
- f.write(u"norm1," + latin1 + u",norm3\n")
- f.write(u"test1,testNonethe" + utf8 + u",test3\n")
+ f.write("norm1,norm2,norm3\n")
+ f.write("norm1," + latin1 + ",norm3\n")
+ f.write("test1,testNonethe" + utf8 + ",test3\n")
with warnings.catch_warnings(record=True) as w:
warnings.filterwarnings('always', '',
np.VisibleDeprecationWarning)
@@ -2583,7 +2583,7 @@ class TestPathUsage:
with temppath(suffix='.txt') as path:
path = Path(path)
with path.open('w') as f:
- f.write(u'A,B\n0,1\n2,3')
+ f.write('A,B\n0,1\n2,3')
kwargs = dict(delimiter=",", missing_values="N/A", names=True)
test = np.recfromtxt(path, **kwargs)
@@ -2596,7 +2596,7 @@ class TestPathUsage:
with temppath(suffix='.txt') as path:
path = Path(path)
with path.open('w') as f:
- f.write(u'A,B\n0,1\n2,3')
+ f.write('A,B\n0,1\n2,3')
kwargs = dict(missing_values="N/A", names=True, case_sensitive=True)
test = np.recfromcsv(path, dtype=None, **kwargs)
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index ba01f3e2e..8c4ad37eb 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -175,7 +175,7 @@ default_filler = {'b': True,
'S': b'N/A',
'u': 999999,
'V': b'???',
- 'U': u'N/A'
+ 'U': 'N/A'
}
# Add datetime64 and timedelta64 types
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index b1c080a56..385e85e5b 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -589,14 +589,14 @@ class TestMaskedArray:
np.set_printoptions(**oldopts)
def test_0d_unicode(self):
- u = u'caf\xe9'
+ u = 'caf\xe9'
utype = type(u)
arr_nomask = np.ma.array(u)
arr_masked = np.ma.array(u, mask=True)
assert_equal(utype(arr_nomask), u)
- assert_equal(utype(arr_masked), u'--')
+ assert_equal(utype(arr_masked), '--')
def test_pickling(self):
# Tests pickling
@@ -5261,7 +5261,7 @@ class TestMaskedConstant:
def test_coercion_unicode(self):
a_u = np.zeros((), 'U10')
a_u[()] = np.ma.masked
- assert_equal(a_u[()], u'--')
+ assert_equal(a_u[()], '--')
@pytest.mark.xfail(reason="See gh-9750")
def test_coercion_bytes(self):
diff --git a/numpy/ma/tests/test_regression.py b/numpy/ma/tests/test_regression.py
index 7e76eb054..cb3d0349f 100644
--- a/numpy/ma/tests/test_regression.py
+++ b/numpy/ma/tests/test_regression.py
@@ -37,7 +37,7 @@ class TestRegression:
def test_masked_array_repr_unicode(self):
# Ticket #1256
- repr(np.ma.array(u"Unicode"))
+ repr(np.ma.array("Unicode"))
def test_atleast_2d(self):
# Ticket #1559