Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1d9dd5

Browse files
authored
Merge pull request #14901 from eric-wieser/remove-uses-of-scalar-aliases
MAINT: Remove uses of scalar aliases
2 parents fae5473 + 6dfe331 commit d1d9dd5

27 files changed

+77
-79
lines changed

doc/neps/roadmap.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ improve the dtype system.
4242
- One of these should probably be the default for text data. The current
4343
behavior on Python 3 is neither efficient nor user friendly.
4444

45-
- `np.int` should not be platform dependent
45+
- ``np.dtype(int)`` should not be platform dependent
4646
- Better coercion for string + number
4747

4848
Performance

doc/source/reference/random/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ cleanup means that legacy and compatibility methods have been removed from
5757
``randint``, ``integers`` Add an ``endpoint`` kwarg
5858
``random_integers``
5959
------------------- -------------- ------------
60-
``tomaxint`` removed Use ``integers(0, np.iinfo(np.int).max,``
60+
``tomaxint`` removed Use ``integers(0, np.iinfo(np.int_).max,``
6161
``endpoint=False)``
6262
------------------- -------------- ------------
6363
``seed`` removed Use `~.SeedSequence.spawn`

doc/source/reference/random/multithreading.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ seed will produce the same outputs.
4141
self.n = n
4242
self.executor = concurrent.futures.ThreadPoolExecutor(threads)
4343
self.values = np.empty(n)
44-
self.step = np.ceil(n / threads).astype(np.int)
44+
self.step = np.ceil(n / threads).astype(np.int_)
4545
4646
def fill(self):
4747
def _fill(random_state, out, first, last):

doc/source/release/1.11.0-notes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ New Features
200200
* A ``dtype`` parameter has been added to ``np.random.randint``
201201
Random ndarrays of the following types can now be generated:
202202

203-
- ``np.bool``,
203+
- ``np.bool_``,
204204
- ``np.int8``, ``np.uint8``,
205205
- ``np.int16``, ``np.uint16``,
206206
- ``np.int32``, ``np.uint32``,

doc/source/release/1.13.0-notes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ In particular ``np.gradient`` can now take:
275275

276276
This means that, e.g., it is now possible to do the following::
277277

278-
>>> f = np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float)
278+
>>> f = np.array([[1, 2, 6], [3, 4, 5]], dtype=np.float_)
279279
>>> dx = 2.
280280
>>> y = [1., 1.5, 3.5]
281281
>>> np.gradient(f, dx, y)

numpy/core/numerictypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def sctype2char(sctype):
485485
486486
Examples
487487
--------
488-
>>> for sctype in [np.int32, np.double, np.complex, np.string_, np.ndarray]:
488+
>>> for sctype in [np.int32, np.double, np.complex_, np.string_, np.ndarray]:
489489
... print(np.sctype2char(sctype))
490490
l # may vary
491491
d

numpy/core/tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ class MyNDArray(np.ndarray):
296296
)
297297
def test_array_astype_warning(t):
298298
# test ComplexWarning when casting from complex to float or int
299-
a = np.array(10, dtype=np.complex)
299+
a = np.array(10, dtype=np.complex_)
300300
assert_warns(np.ComplexWarning, a.astype, t)
301301

302302
def test_copyto_fromscalar():

numpy/core/tests/test_dtype.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def assert_dtype_not_equal(a, b):
2525

2626
class TestBuiltin(object):
2727
@pytest.mark.parametrize('t', [int, float, complex, np.int32, str, object,
28-
np.unicode])
28+
np.compat.unicode])
2929
def test_run(self, t):
3030
"""Only test hash runs at all."""
3131
dt = np.dtype(t)
@@ -986,7 +986,7 @@ def check_pickling(self, dtype):
986986
assert_equal(x[0], y[0])
987987

988988
@pytest.mark.parametrize('t', [int, float, complex, np.int32, str, object,
989-
np.unicode, bool])
989+
np.compat.unicode, bool])
990990
def test_builtin(self, t):
991991
self.check_pickling(np.dtype(t))
992992

numpy/core/tests/test_multiarray.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ def test_sequence_non_homogenous(self):
964964

965965
@pytest.mark.skipif(sys.version_info[0] >= 3, reason="Not Python 2")
966966
def test_sequence_long(self):
967-
assert_equal(np.array([long(4), long(4)]).dtype, np.long)
967+
assert_equal(np.array([long(4), long(4)]).dtype, long)
968968
assert_equal(np.array([long(4), 2**80]).dtype, object)
969969
assert_equal(np.array([long(4), 2**80, long(4)]).dtype, object)
970970
assert_equal(np.array([2**80, long(4)]).dtype, object)
@@ -1807,7 +1807,7 @@ def test_sort(self):
18071807

18081808
# test unicode sorts.
18091809
s = 'aaaaaaaa'
1810-
a = np.array([s + chr(i) for i in range(101)], dtype=np.unicode)
1810+
a = np.array([s + chr(i) for i in range(101)], dtype=np.unicode_)
18111811
b = a[::-1].copy()
18121812
for kind in self.sort_kinds:
18131813
msg = "unicode sort, kind=%s" % kind
@@ -2059,7 +2059,7 @@ def test_argsort(self):
20592059

20602060
# test unicode argsorts.
20612061
s = 'aaaaaaaa'
2062-
a = np.array([s + chr(i) for i in range(101)], dtype=np.unicode)
2062+
a = np.array([s + chr(i) for i in range(101)], dtype=np.unicode_)
20632063
b = a[::-1]
20642064
r = np.arange(101)
20652065
rr = r[::-1]
@@ -2142,7 +2142,7 @@ def test_argsort(self):
21422142
a = np.array(['aaaaaaaaa' for i in range(100)])
21432143
assert_equal(a.argsort(kind='m'), r)
21442144
# unicode
2145-
a = np.array(['aaaaaaaaa' for i in range(100)], dtype=np.unicode)
2145+
a = np.array(['aaaaaaaaa' for i in range(100)], dtype=np.unicode_)
21462146
assert_equal(a.argsort(kind='m'), r)
21472147

21482148
def test_sort_unicode_kind(self):
@@ -2271,7 +2271,7 @@ def test_searchsorted_unicode(self):
22712271
'P:\\20x_dapi_cy3\\20x_dapi_cy3_20100197_1',
22722272
'P:\\20x_dapi_cy3\\20x_dapi_cy3_20100198_1',
22732273
'P:\\20x_dapi_cy3\\20x_dapi_cy3_20100199_1'],
2274-
dtype=np.unicode)
2274+
dtype=np.unicode_)
22752275
ind = np.arange(len(a))
22762276
assert_equal([a.searchsorted(v, 'left') for v in a], ind)
22772277
assert_equal([a.searchsorted(v, 'right') for v in a], ind + 1)
@@ -7930,20 +7930,20 @@ def test_null_inside_bstring_array_is_truthy(self):
79307930
class TestUnicodeArrayNonzero(object):
79317931

79327932
def test_empty_ustring_array_is_falsey(self):
7933-
assert_(not np.array([''], dtype=np.unicode))
7933+
assert_(not np.array([''], dtype=np.unicode_))
79347934

79357935
def test_whitespace_ustring_array_is_falsey(self):
7936-
a = np.array(['eggs'], dtype=np.unicode)
7936+
a = np.array(['eggs'], dtype=np.unicode_)
79377937
a[0] = ' \0\0'
79387938
assert_(not a)
79397939

79407940
def test_all_null_ustring_array_is_falsey(self):
7941-
a = np.array(['eggs'], dtype=np.unicode)
7941+
a = np.array(['eggs'], dtype=np.unicode_)
79427942
a[0] = '\0\0\0\0'
79437943
assert_(not a)
79447944

79457945
def test_null_inside_ustring_array_is_truthy(self):
7946-
a = np.array(['eggs'], dtype=np.unicode)
7946+
a = np.array(['eggs'], dtype=np.unicode_)
79477947
a[0] = ' \0 \0'
79487948
assert_(a)
79497949

numpy/core/tests/test_nditer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ def test_iter_buffering_string():
21042104
assert_equal(i[0], b'abc')
21052105
assert_equal(i[0].dtype, np.dtype('S6'))
21062106

2107-
a = np.array(['abc', 'a', 'abcd'], dtype=np.unicode)
2107+
a = np.array(['abc', 'a', 'abcd'], dtype=np.unicode_)
21082108
assert_equal(a.dtype, np.dtype('U4'))
21092109
assert_raises(TypeError, nditer, a, ['buffered'], ['readonly'],
21102110
op_dtypes='U2')

numpy/core/tests/test_numeric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2953,7 +2953,7 @@ def test_sparse(self):
29532953
assert_array_equal(x, np.array([[0], [1], [2], [3]]))
29542954
assert_array_equal(y, np.array([[0, 1, 2]]))
29552955

2956-
@pytest.mark.parametrize("dtype", [np.int, np.float32, np.float64])
2956+
@pytest.mark.parametrize("dtype", [np.int32, np.int64, np.float32, np.float64])
29572957
@pytest.mark.parametrize("dims", [(), (0,), (4, 3)])
29582958
def test_return_type(self, dtype, dims):
29592959
inds = np.indices(dims, dtype=dtype)

numpy/core/tests/test_regression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,7 +1511,7 @@ def test_type(t):
15111511
min //= -1
15121512

15131513
with np.errstate(divide="ignore"):
1514-
for t in (np.int8, np.int16, np.int32, np.int64, int, np.long):
1514+
for t in (np.int8, np.int16, np.int32, np.int64, int, np.compat.long):
15151515
test_type(t)
15161516

15171517
def test_buffer_hashlib(self):
@@ -2112,7 +2112,7 @@ def test_unicode_alloc_dealloc_match(self):
21122112
# Ticket #1578, the mismatch only showed up when running
21132113
# python-debug for python versions >= 2.7, and then as
21142114
# a core dump and error message.
2115-
a = np.array(['abc'], dtype=np.unicode)[0]
2115+
a = np.array(['abc'], dtype=np.unicode_)[0]
21162116
del a
21172117

21182118
def test_refcount_error_in_clip(self):

numpy/core/tests/test_scalarinherit.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ class Mystr(str, np.generic):
6868
def test_char_repeat(self):
6969
np_s = np.string_('abc')
7070
np_u = np.unicode_('abc')
71-
np_i = np.int(5)
7271
res_s = b'abc' * 5
7372
res_u = u'abc' * 5
74-
assert_(np_s * np_i == res_s)
75-
assert_(np_u * np_i == res_u)
73+
assert_(np_s * 5 == res_s)
74+
assert_(np_u * 5 == res_u)

numpy/core/tests/test_ufunc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ def test_can_ignore_signature(self):
980980
assert_array_equal(out, mm_row_col_vec.squeeze())
981981

982982
def test_matrix_multiply(self):
983-
self.compare_matrix_multiply_results(np.long)
983+
self.compare_matrix_multiply_results(np.int64)
984984
self.compare_matrix_multiply_results(np.double)
985985

986986
def test_matrix_multiply_umath_empty(self):

numpy/core/tests/test_umath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ def test_log_float32(self):
792792
def test_sincos_float32(self):
793793
np.random.seed(42)
794794
N = 1000000
795-
M = np.int(N/20)
795+
M = np.int_(N/20)
796796
index = np.random.randint(low=0, high=N, size=M)
797797
x_f32 = np.float32(np.random.uniform(low=-100.,high=100.,size=N))
798798
# test coverage for elements > 117435.992f for which glibc is used

numpy/core/tests/test_umath_accuracy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_validate_transcendentals(self):
3838
with open(filepath) as fid:
3939
file_without_comments = (r for r in fid if not r[0] in ('$', '#'))
4040
data = np.genfromtxt(file_without_comments,
41-
dtype=('|S39','|S39','|S39',np.int),
41+
dtype=('|S39','|S39','|S39',int),
4242
names=('type','input','output','ulperr'),
4343
delimiter=',',
4444
skip_header=1)

numpy/doc/basics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- C type
1919
- Description
2020
21-
* - `np.bool`
21+
* - `np.bool_`
2222
- ``bool``
2323
- Boolean (True or False) stored as a byte
2424
@@ -283,7 +283,7 @@
283283
minimum or maximum values of NumPy integer and floating point values
284284
respectively ::
285285
286-
>>> np.iinfo(np.int) # Bounds of the default integer on this system.
286+
>>> np.iinfo(int) # Bounds of the default integer on this system.
287287
iinfo(min=-9223372036854775808, max=9223372036854775807, dtype=int64)
288288
>>> np.iinfo(np.int32) # Bounds of a 32-bit integer
289289
iinfo(min=-2147483648, max=2147483647, dtype=int32)

numpy/lib/npyio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,9 +1529,9 @@ def fromregex(file, regexp, dtype, encoding=None):
15291529
dtype = np.dtype(dtype)
15301530

15311531
content = file.read()
1532-
if isinstance(content, bytes) and isinstance(regexp, np.unicode):
1532+
if isinstance(content, bytes) and isinstance(regexp, np.compat.unicode):
15331533
regexp = asbytes(regexp)
1534-
elif isinstance(content, np.unicode) and isinstance(regexp, bytes):
1534+
elif isinstance(content, np.compat.unicode) and isinstance(regexp, bytes):
15351535
regexp = asstr(regexp)
15361536

15371537
if not hasattr(regexp, 'match'):

numpy/lib/tests/test_io.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -518,15 +518,15 @@ def write(self, text):
518518

519519
def test_unicode(self):
520520
utf8 = b'\xcf\x96'.decode('UTF-8')
521-
a = np.array([utf8], dtype=np.unicode)
521+
a = np.array([utf8], dtype=np.unicode_)
522522
with tempdir() as tmpdir:
523523
# set encoding as on windows it may not be unicode even on py3
524524
np.savetxt(os.path.join(tmpdir, 'test.csv'), a, fmt=['%s'],
525525
encoding='UTF-8')
526526

527527
def test_unicode_roundtrip(self):
528528
utf8 = b'\xcf\x96'.decode('UTF-8')
529-
a = np.array([utf8], dtype=np.unicode)
529+
a = np.array([utf8], dtype=np.unicode_)
530530
# our gz wrapper support encoding
531531
suffixes = ['', '.gz']
532532
# stdlib 2 versions do not support encoding
@@ -540,20 +540,20 @@ def test_unicode_roundtrip(self):
540540
np.savetxt(os.path.join(tmpdir, 'test.csv' + suffix), a,
541541
fmt=['%s'], encoding='UTF-16-LE')
542542
b = np.loadtxt(os.path.join(tmpdir, 'test.csv' + suffix),
543-
encoding='UTF-16-LE', dtype=np.unicode)
543+
encoding='UTF-16-LE', dtype=np.unicode_)
544544
assert_array_equal(a, b)
545545

546546
def test_unicode_bytestream(self):
547547
utf8 = b'\xcf\x96'.decode('UTF-8')
548-
a = np.array([utf8], dtype=np.unicode)
548+
a = np.array([utf8], dtype=np.unicode_)
549549
s = BytesIO()
550550
np.savetxt(s, a, fmt=['%s'], encoding='UTF-8')
551551
s.seek(0)
552552
assert_equal(s.read().decode('UTF-8'), utf8 + '\n')
553553

554554
def test_unicode_stringstream(self):
555555
utf8 = b'\xcf\x96'.decode('UTF-8')
556-
a = np.array([utf8], dtype=np.unicode)
556+
a = np.array([utf8], dtype=np.unicode_)
557557
s = StringIO()
558558
np.savetxt(s, a, fmt=['%s'], encoding='UTF-8')
559559
s.seek(0)
@@ -632,20 +632,20 @@ def test_stringload(self):
632632
with temppath() as path:
633633
with open(path, "wb") as f:
634634
f.write(nonascii.encode("UTF-16"))
635-
x = self.loadfunc(path, encoding="UTF-16", dtype=np.unicode)
635+
x = self.loadfunc(path, encoding="UTF-16", dtype=np.unicode_)
636636
assert_array_equal(x, nonascii)
637637

638638
def test_binary_decode(self):
639639
utf16 = b'\xff\xfeh\x04 \x00i\x04 \x00j\x04'
640-
v = self.loadfunc(BytesIO(utf16), dtype=np.unicode, encoding='UTF-16')
640+
v = self.loadfunc(BytesIO(utf16), dtype=np.unicode_, encoding='UTF-16')
641641
assert_array_equal(v, np.array(utf16.decode('UTF-16').split()))
642642

643643
def test_converters_decode(self):
644644
# test converters that decode strings
645645
c = TextIO()
646646
c.write(b'\xcf\x96')
647647
c.seek(0)
648-
x = self.loadfunc(c, dtype=np.unicode,
648+
x = self.loadfunc(c, dtype=np.unicode_,
649649
converters={0: lambda x: x.decode('UTF-8')})
650650
a = np.array([b'\xcf\x96'.decode('UTF-8')])
651651
assert_array_equal(x, a)
@@ -656,7 +656,7 @@ def test_converters_nodecode(self):
656656
with temppath() as path:
657657
with io.open(path, 'wt', encoding='UTF-8') as f:
658658
f.write(utf8)
659-
x = self.loadfunc(path, dtype=np.unicode,
659+
x = self.loadfunc(path, dtype=np.unicode_,
660660
converters={0: lambda x: x + 't'},
661661
encoding='UTF-8')
662662
a = np.array([utf8 + 't'])
@@ -1104,7 +1104,7 @@ def test_binary_load(self):
11041104
with open(path, "wb") as f:
11051105
f.write(butf8)
11061106
with open(path, "rb") as f:
1107-
x = np.loadtxt(f, encoding="UTF-8", dtype=np.unicode)
1107+
x = np.loadtxt(f, encoding="UTF-8", dtype=np.unicode_)
11081108
assert_array_equal(x, sutf8)
11091109
# test broken latin1 conversion people now rely on
11101110
with open(path, "rb") as f:
@@ -1587,7 +1587,7 @@ def test_utf8_userconverters_with_explicit_dtype(self):
15871587
with open(path, 'wb') as f:
15881588
f.write(b'skip,skip,2001-01-01' + utf8 + b',1.0,skip')
15891589
test = np.genfromtxt(path, delimiter=",", names=None, dtype=float,
1590-
usecols=(2, 3), converters={2: np.unicode},
1590+
usecols=(2, 3), converters={2: np.compat.unicode},
15911591
encoding='UTF-8')
15921592
control = np.array([('2001-01-01' + utf8.decode('UTF-8'), 1.)],
15931593
dtype=[('', '|U11'), ('', float)])
@@ -2126,7 +2126,7 @@ def test_utf8_file(self):
21262126
ctl = np.array([
21272127
["test1", "testNonethe" + utf8.decode("UTF-8"), "test3"],
21282128
["test1", "testNonethe" + utf8.decode("UTF-8"), "test3"]],
2129-
dtype=np.unicode)
2129+
dtype=np.unicode_)
21302130
assert_array_equal(test, ctl)
21312131

21322132
# test a mixed dtype
@@ -2169,7 +2169,7 @@ def test_utf8_file_nodtype_unicode(self):
21692169
["norm1", "norm2", "norm3"],
21702170
["norm1", latin1, "norm3"],
21712171
["test1", "testNonethe" + utf8, "test3"]],
2172-
dtype=np.unicode)
2172+
dtype=np.unicode_)
21732173
assert_array_equal(test, ctl)
21742174

21752175
def test_recfromtxt(self):

numpy/lib/tests/test_ufunclike.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_isposinf(self):
2121
assert_equal(res, tgt)
2222
assert_equal(out, tgt)
2323

24-
a = a.astype(np.complex)
24+
a = a.astype(np.complex_)
2525
with assert_raises(TypeError):
2626
ufl.isposinf(a)
2727

@@ -36,7 +36,7 @@ def test_isneginf(self):
3636
assert_equal(res, tgt)
3737
assert_equal(out, tgt)
3838

39-
a = a.astype(np.complex)
39+
a = a.astype(np.complex_)
4040
with assert_raises(TypeError):
4141
ufl.isneginf(a)
4242

0 commit comments

Comments
 (0)