summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/core/tests/test_array_coercion.py2
-rw-r--r--numpy/core/tests/test_casting_unittests.py6
-rw-r--r--numpy/core/tests/test_dtype.py4
-rw-r--r--numpy/core/tests/test_einsum.py7
-rw-r--r--numpy/core/tests/test_getlimits.py4
-rw-r--r--numpy/core/tests/test_multiarray.py7
-rw-r--r--numpy/core/tests/test_numeric.py11
-rw-r--r--numpy/core/tests/test_regression.py6
-rw-r--r--numpy/core/tests/test_scalar_ctors.py3
-rw-r--r--numpy/core/tests/test_scalarmath.py7
-rw-r--r--numpy/core/tests/test_umath.py26
-rw-r--r--numpy/f2py/tests/test_return_complex.py2
-rw-r--r--numpy/f2py/tests/test_return_real.py2
13 files changed, 50 insertions, 37 deletions
diff --git a/numpy/core/tests/test_array_coercion.py b/numpy/core/tests/test_array_coercion.py
index 3a074a2b5..fade57292 100644
--- a/numpy/core/tests/test_array_coercion.py
+++ b/numpy/core/tests/test_array_coercion.py
@@ -375,7 +375,7 @@ class TestScalarDiscovery:
@pytest.mark.parametrize("dtype", np.typecodes["Integer"])
@pytest.mark.parametrize(["scalar", "error"],
[(np.float64(np.nan), ValueError),
- (np.ulonglong(-1), OverflowError)])
+ (np.array(-1).astype(np.ulonglong)[()], OverflowError)])
def test_scalar_to_int_coerce_does_not_cast(self, dtype, scalar, error):
"""
Signed integers are currently different in that they do not cast other
diff --git a/numpy/core/tests/test_casting_unittests.py b/numpy/core/tests/test_casting_unittests.py
index 16ecb1943..a49d876d4 100644
--- a/numpy/core/tests/test_casting_unittests.py
+++ b/numpy/core/tests/test_casting_unittests.py
@@ -169,6 +169,9 @@ class TestCasting:
for i, value in enumerate(values):
# Use item assignment to ensure this is not using casting:
+ if value < 0 and dtype1.kind == "u":
+ # Manually rollover unsigned integers (-1 -> int.max)
+ value = value + np.iinfo(dtype1).max + 1
arr1[i] = value
if dtype2 is None:
@@ -185,6 +188,9 @@ class TestCasting:
for i, value in enumerate(values):
# Use item assignment to ensure this is not using casting:
+ if value < 0 and dtype2.kind == "u":
+ # Manually rollover unsigned integers (-1 -> int.max)
+ value = value + np.iinfo(dtype2).max + 1
arr2[i] = value
return arr1, arr2, values
diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py
index 9b471a5bf..f7819e83b 100644
--- a/numpy/core/tests/test_dtype.py
+++ b/numpy/core/tests/test_dtype.py
@@ -328,8 +328,8 @@ class TestRecord:
dt2 = np.dtype({'names':['f2', 'f0', 'f1'],
'formats':['<u4', '<u2', '<u2'],
'offsets':[4, 0, 2]}, align=True)
- vals = [(0, 1, 2), (3, -1, 4)]
- vals2 = [(0, 1, 2), (3, -1, 4)]
+ vals = [(0, 1, 2), (3, 2**15-1, 4)]
+ vals2 = [(0, 1, 2), (3, 2**15-1, 4)]
a = np.array(vals, dt)
b = np.array(vals2, dt2)
assert_equal(a.astype(dt2), b)
diff --git a/numpy/core/tests/test_einsum.py b/numpy/core/tests/test_einsum.py
index ea96f0fef..623ebcbe2 100644
--- a/numpy/core/tests/test_einsum.py
+++ b/numpy/core/tests/test_einsum.py
@@ -241,6 +241,7 @@ class TestEinsum:
@np._no_nep50_warning()
def check_einsum_sums(self, dtype, do_opt=False):
+ dtype = np.dtype(dtype)
# Check various sums. Does many sizes to exercise unrolled loops.
# sum(a, axis=-1)
@@ -442,9 +443,11 @@ class TestEinsum:
axes=([1, 0], [0, 1])).astype(dtype))
# logical_and(logical_and(a!=0, b!=0), c!=0)
- a = np.array([1, 3, -2, 0, 12, 13, 0, 1], dtype=dtype)
- b = np.array([0, 3.5, 0., -2, 0, 1, 3, 12], dtype=dtype)
+ neg_val = -2 if dtype.kind != "u" else np.iinfo(dtype).max - 1
+ a = np.array([1, 3, neg_val, 0, 12, 13, 0, 1], dtype=dtype)
+ b = np.array([0, 3.5, 0., neg_val, 0, 1, 3, 12], dtype=dtype)
c = np.array([True, True, False, True, True, False, True, True])
+
assert_equal(np.einsum("i,i,i->i", a, b, c,
dtype='?', casting='unsafe', optimize=do_opt),
np.logical_and(np.logical_and(a != 0, b != 0), c != 0))
diff --git a/numpy/core/tests/test_getlimits.py b/numpy/core/tests/test_getlimits.py
index c5148db2c..b8aaba386 100644
--- a/numpy/core/tests/test_getlimits.py
+++ b/numpy/core/tests/test_getlimits.py
@@ -69,7 +69,9 @@ class TestIinfo:
def test_unsigned_max(self):
types = np.sctypes['uint']
for T in types:
- assert_equal(iinfo(T).max, T(-1))
+ with np.errstate(over="ignore"):
+ max_calculated = T(0) - T(1)
+ assert_equal(iinfo(T).max, max_calculated)
class TestRepr:
def test_iinfo_repr(self):
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 87317cc92..a9a21e8c3 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -5020,6 +5020,8 @@ class TestPutmask:
for types in np.sctypes.values():
for T in types:
if T not in unchecked_types:
+ if val < 0 and np.dtype(T).kind == "u":
+ val = np.iinfo(T).max - 99
self.tst_basic(x.copy().astype(T), T, mask, val)
# Also test string of a length which uses an untypical length
@@ -7234,9 +7236,8 @@ class TestInner:
[2630, 2910, 3190]],
[[2198, 2542, 2886],
- [3230, 3574, 3918]]]],
- dtype=dt
- )
+ [3230, 3574, 3918]]]]
+ ).astype(dt)
assert_equal(np.inner(a, b), desired)
assert_equal(np.inner(b, a).transpose(2,3,0,1), desired)
diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py
index 21bf91a35..bc4ba9f72 100644
--- a/numpy/core/tests/test_numeric.py
+++ b/numpy/core/tests/test_numeric.py
@@ -2824,12 +2824,11 @@ class TestLikeFuncs:
def compare_array_value(self, dz, value, fill_value):
if value is not None:
if fill_value:
- try:
- z = dz.dtype.type(value)
- except OverflowError:
- pass
- else:
- assert_(np.all(dz == z))
+ # Conversion is close to what np.full_like uses
+ # but we may want to convert directly in the future
+ # which may result in errors (where this does not).
+ z = np.array(value).astype(dz.dtype)
+ assert_(np.all(dz == z))
else:
assert_(np.all(dz == value))
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 4538c825d..2f2d115a4 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1922,7 +1922,7 @@ class TestRegression:
# Check that loads does not clobber interned strings
s = re.sub("a(.)", "\x01\\1", "a_")
assert_equal(s[0], "\x01")
- data[0] = 0xbb
+ data[0] = 0x6a
s = re.sub("a(.)", "\x01\\1", "a_")
assert_equal(s[0], "\x01")
@@ -1930,7 +1930,7 @@ class TestRegression:
for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
data = np.array([1], dtype='b')
data = pickle.loads(pickle.dumps(data, protocol=proto))
- data[0] = 0xdd
+ data[0] = 0x7d
bytestring = "\x01 ".encode('ascii')
assert_equal(bytestring[0:1], '\x01'.encode('ascii'))
@@ -1945,7 +1945,7 @@ class TestRegression:
b"p13\ntp14\nb.")
# This should work:
result = pickle.loads(data, encoding='latin1')
- assert_array_equal(result, np.array([129], dtype='b'))
+ assert_array_equal(result, np.array([129]).astype('b'))
# Should not segfault:
assert_raises(Exception, pickle.loads, data, encoding='koi8-r')
diff --git a/numpy/core/tests/test_scalar_ctors.py b/numpy/core/tests/test_scalar_ctors.py
index 7e933537d..17aca3fb8 100644
--- a/numpy/core/tests/test_scalar_ctors.py
+++ b/numpy/core/tests/test_scalar_ctors.py
@@ -78,7 +78,8 @@ class TestFromInt:
assert_equal(1024, np.intp(1024))
def test_uint64_from_negative(self):
- assert_equal(np.uint64(-2), np.uint64(18446744073709551614))
+ with pytest.warns(DeprecationWarning):
+ assert_equal(np.uint64(-2), np.uint64(18446744073709551614))
int_types = [np.byte, np.short, np.intc, np.int_, np.longlong]
diff --git a/numpy/core/tests/test_scalarmath.py b/numpy/core/tests/test_scalarmath.py
index 3830ec0c7..6d9f0a46d 100644
--- a/numpy/core/tests/test_scalarmath.py
+++ b/numpy/core/tests/test_scalarmath.py
@@ -442,7 +442,8 @@ class TestConversion:
def test_iinfo_long_values(self):
for code in 'bBhH':
- res = np.array(np.iinfo(code).max + 1, dtype=code)
+ with pytest.warns(DeprecationWarning):
+ res = np.array(np.iinfo(code).max + 1, dtype=code)
tgt = np.iinfo(code).min
assert_(res == tgt)
@@ -767,7 +768,7 @@ class TestBitShifts:
nbits = dt.itemsize * 8
for val in [5, -5]:
for shift in [nbits, nbits + 4]:
- val_scl = dt.type(val)
+ val_scl = np.array(val).astype(dt)[()]
shift_scl = dt.type(shift)
res_scl = op(val_scl, shift_scl)
if val_scl < 0 and op is operator.rshift:
@@ -777,7 +778,7 @@ class TestBitShifts:
assert_equal(res_scl, 0)
# Result on scalars should be the same as on arrays
- val_arr = np.array([val]*32, dtype=dt)
+ val_arr = np.array([val_scl]*32, dtype=dt)
shift_arr = np.array([shift]*32, dtype=dt)
res_arr = op(val_arr, shift_arr)
assert_equal(res_arr, res_scl)
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index afe42b56a..ff2b6a0f2 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -366,24 +366,24 @@ class TestDivision:
np.sctypes['int'] + np.sctypes['uint'], (
(
# dividend
- "np.arange(fo.max-lsize, fo.max, dtype=dtype),"
+ "np.array(range(fo.max-lsize, fo.max)).astype(dtype),"
# divisors
- "np.arange(lsize, dtype=dtype),"
+ "np.arange(lsize).astype(dtype),"
# scalar divisors
"range(15)"
),
(
# dividend
- "np.arange(fo.min, fo.min+lsize, dtype=dtype),"
+ "np.arange(fo.min, fo.min+lsize).astype(dtype),"
# divisors
- "np.arange(lsize//-2, lsize//2, dtype=dtype),"
+ "np.arange(lsize//-2, lsize//2).astype(dtype),"
# scalar divisors
"range(fo.min, fo.min + 15)"
), (
# dividend
- "np.arange(fo.max-lsize, fo.max, dtype=dtype),"
+ "np.array(range(fo.max-lsize, fo.max)).astype(dtype),"
# divisors
- "np.arange(lsize, dtype=dtype),"
+ "np.arange(lsize).astype(dtype),"
# scalar divisors
"[1,3,9,13,neg, fo.min+1, fo.min//2, fo.max//3, fo.max//4]"
)
@@ -450,9 +450,9 @@ class TestDivision:
@pytest.mark.parametrize("dtype,ex_val", itertools.product(
np.sctypes['int'] + np.sctypes['uint'], (
"np.array([fo.max, 1, 2, 1, 1, 2, 3], dtype=dtype)",
- "np.array([fo.min, 1, -2, 1, 1, 2, -3], dtype=dtype)",
+ "np.array([fo.min, 1, -2, 1, 1, 2, -3]).astype(dtype)",
"np.arange(fo.min, fo.min+(100*10), 10, dtype=dtype)",
- "np.arange(fo.max-(100*7), fo.max, 7, dtype=dtype)",
+ "np.array(range(fo.max-(100*7), fo.max, 7)).astype(dtype)",
)
))
def test_division_int_reduce(self, dtype, ex_val):
@@ -472,7 +472,7 @@ class TestDivision:
with np.errstate(divide='raise', over='raise'):
with pytest.raises(FloatingPointError,
match="divide by zero encountered in reduce"):
- np.floor_divide.reduce(np.arange(-100, 100, dtype=dtype))
+ np.floor_divide.reduce(np.arange(-100, 100).astype(dtype))
if fo.min:
with pytest.raises(FloatingPointError,
match='overflow encountered in reduce'):
@@ -2328,7 +2328,7 @@ class TestBitwiseUFuncs:
def test_values(self):
for dt in self.bitwise_types:
zeros = np.array([0], dtype=dt)
- ones = np.array([-1], dtype=dt)
+ ones = np.array([-1]).astype(dt)
msg = "dt = '%s'" % dt.char
assert_equal(np.bitwise_not(zeros), ones, err_msg=msg)
@@ -2352,7 +2352,7 @@ class TestBitwiseUFuncs:
def test_types(self):
for dt in self.bitwise_types:
zeros = np.array([0], dtype=dt)
- ones = np.array([-1], dtype=dt)
+ ones = np.array([-1]).astype(dt)
msg = "dt = '%s'" % dt.char
assert_(np.bitwise_not(zeros).dtype == dt, msg)
@@ -2370,7 +2370,7 @@ class TestBitwiseUFuncs:
for dt in self.bitwise_types:
zeros = np.array([0], dtype=dt)
- ones = np.array([-1], dtype=dt)
+ ones = np.array([-1]).astype(dt)
for f in binary_funcs:
msg = "dt: '%s', f: '%s'" % (dt, f)
assert_equal(f.reduce(zeros), zeros, err_msg=msg)
@@ -2382,7 +2382,7 @@ class TestBitwiseUFuncs:
empty = np.array([], dtype=dt)
for f in binary_funcs:
msg = "dt: '%s', f: '%s'" % (dt, f)
- tgt = np.array(f.identity, dtype=dt)
+ tgt = np.array(f.identity).astype(dt)
res = f.reduce(empty)
assert_equal(res, tgt, err_msg=msg)
assert_(res.dtype == tgt.dtype, msg)
diff --git a/numpy/f2py/tests/test_return_complex.py b/numpy/f2py/tests/test_return_complex.py
index dc5592899..9df79632d 100644
--- a/numpy/f2py/tests/test_return_complex.py
+++ b/numpy/f2py/tests/test_return_complex.py
@@ -23,7 +23,7 @@ class TestReturnComplex(util.F2PyTest):
assert abs(t(array(23 + 4j, "F")) - (23 + 4j)) <= err
assert abs(t(array([234])) - 234.0) <= err
assert abs(t(array([[234]])) - 234.0) <= err
- assert abs(t(array([234], "b")) + 22.0) <= err
+ assert abs(t(array([234]).astype("b")) + 22.0) <= err
assert abs(t(array([234], "h")) - 234.0) <= err
assert abs(t(array([234], "i")) - 234.0) <= err
assert abs(t(array([234], "l")) - 234.0) <= err
diff --git a/numpy/f2py/tests/test_return_real.py b/numpy/f2py/tests/test_return_real.py
index 7705a1122..9e76c151e 100644
--- a/numpy/f2py/tests/test_return_real.py
+++ b/numpy/f2py/tests/test_return_real.py
@@ -22,7 +22,7 @@ class TestReturnReal(util.F2PyTest):
assert abs(t(array(234)) - 234.0) <= err
assert abs(t(array([234])) - 234.0) <= err
assert abs(t(array([[234]])) - 234.0) <= err
- assert abs(t(array([234], "b")) + 22) <= err
+ assert abs(t(array([234]).astype("b")) + 22) <= err
assert abs(t(array([234], "h")) - 234.0) <= err
assert abs(t(array([234], "i")) - 234.0) <= err
assert abs(t(array([234], "l")) - 234.0) <= err