summaryrefslogtreecommitdiff
path: root/numpy/core/tests/test_regression.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/tests/test_regression.py')
-rw-r--r--numpy/core/tests/test_regression.py61
1 files changed, 33 insertions, 28 deletions
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index c3b9dab69..841144790 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -12,7 +12,7 @@ from numpy.testing import (
assert_, assert_equal, IS_PYPY, assert_almost_equal,
assert_array_equal, assert_array_almost_equal, assert_raises,
assert_raises_regex, assert_warns, suppress_warnings,
- _assert_valid_refcount, HAS_REFCOUNT, IS_PYSTON
+ _assert_valid_refcount, HAS_REFCOUNT, IS_PYSTON, IS_WASM
)
from numpy.testing._private.utils import _no_tracing, requires_memory
from numpy.compat import asbytes, asunicode, pickle
@@ -128,10 +128,7 @@ class TestRegression:
assert_(a[1] == 'auto')
assert_(a[0] != 'auto')
b = np.linspace(0, 10, 11)
- # This should return true for now, but will eventually raise an error:
- with suppress_warnings() as sup:
- sup.filter(FutureWarning)
- assert_(b != 'auto')
+ assert_array_equal(b != 'auto', np.ones(11, dtype=bool))
assert_(b[0] != 'auto')
def test_unicode_swapping(self):
@@ -295,7 +292,7 @@ class TestRegression:
def test_unicode_string_comparison(self):
# Ticket #190
- a = np.array('hello', np.unicode_)
+ a = np.array('hello', np.str_)
b = np.array('world')
a == b
@@ -326,6 +323,7 @@ class TestRegression:
assert_raises(ValueError, bfa)
assert_raises(ValueError, bfb)
+ @pytest.mark.xfail(IS_WASM, reason="not sure why")
@pytest.mark.parametrize("index",
[np.ones(10, dtype=bool), np.arange(10)],
ids=["boolean-arr-index", "integer-arr-index"])
@@ -457,7 +455,7 @@ class TestRegression:
test_data = [
# (original, py2_pickle)
- (np.unicode_('\u6f2c'),
+ (np.str_('\u6f2c'),
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."),
@@ -518,22 +516,15 @@ class TestRegression:
def test_method_args(self):
# Make sure methods and functions have same default axis
# keyword and arguments
- funcs1 = ['argmax', 'argmin', 'sum', ('product', 'prod'),
- ('sometrue', 'any'),
- ('alltrue', 'all'), 'cumsum', ('cumproduct', 'cumprod'),
- 'ptp', 'cumprod', 'prod', 'std', 'var', 'mean',
- 'round', 'min', 'max', 'argsort', 'sort']
+ funcs1 = ['argmax', 'argmin', 'sum', 'any', 'all', 'cumsum',
+ 'ptp', 'cumprod', 'prod', 'std', 'var', 'mean',
+ 'round', 'min', 'max', 'argsort', 'sort']
funcs2 = ['compress', 'take', 'repeat']
for func in funcs1:
arr = np.random.rand(8, 7)
arr2 = arr.copy()
- if isinstance(func, tuple):
- func_meth = func[1]
- func = func[0]
- else:
- func_meth = func
- res1 = getattr(arr, func_meth)()
+ res1 = getattr(arr, func)()
res2 = getattr(np, func)(arr2)
if res1 is None:
res1 = arr
@@ -1338,8 +1329,8 @@ class TestRegression:
# Ticket #1058
a = np.fromiter(list(range(10)), dtype='b')
b = np.fromiter(list(range(10)), dtype='B')
- assert_(np.alltrue(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
- assert_(np.alltrue(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
+ assert_(np.all(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
+ assert_(np.all(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
def test_array_from_sequence_scalar_array(self):
# Ticket #1078: segfaults when creating an array with a sequence of
@@ -1517,8 +1508,8 @@ class TestRegression:
def test_fromiter_comparison(self):
a = np.fromiter(list(range(10)), dtype='b')
b = np.fromiter(list(range(10)), dtype='B')
- assert_(np.alltrue(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
- assert_(np.alltrue(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
+ assert_(np.all(a == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
+ assert_(np.all(b == np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])))
def test_fromstring_crash(self):
# Ticket #1345: the following should not cause a crash
@@ -1537,9 +1528,12 @@ class TestRegression:
for y in dtypes:
c = a.astype(y)
try:
- np.dot(b, c)
+ d = np.dot(b, c)
except TypeError:
failures.append((x, y))
+ else:
+ if d != 0:
+ failures.append((x, y))
if failures:
raise AssertionError("Failures: %r" % failures)
@@ -1689,7 +1683,7 @@ class TestRegression:
# number 2, and the exception hung around until something checked
# PyErr_Occurred() and returned an error.
assert_equal(np.dtype('S10').itemsize, 10)
- np.array([['abc', 2], ['long ', '0123456789']], dtype=np.string_)
+ np.array([['abc', 2], ['long ', '0123456789']], dtype=np.bytes_)
assert_equal(np.dtype('S10').itemsize, 10)
def test_any_float(self):
@@ -1958,7 +1952,7 @@ class TestRegression:
# Python2 output for pickle.dumps(...)
datas = [
# (original, python2_pickle, koi8r_validity)
- (np.unicode_('\u6bd2'),
+ (np.str_('\u6bd2'),
(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."),
@@ -2082,7 +2076,7 @@ class TestRegression:
# Ticket #1578, the mismatch only showed up when running
# python-debug for python versions >= 2.7, and then as
# a core dump and error message.
- a = np.array(['abc'], dtype=np.unicode_)[0]
+ a = np.array(['abc'], dtype=np.str_)[0]
del a
def test_refcount_error_in_clip(self):
@@ -2229,7 +2223,7 @@ class TestRegression:
def test_pickle_empty_string(self):
# gh-3926
for proto in range(2, pickle.HIGHEST_PROTOCOL + 1):
- test_string = np.string_('')
+ test_string = np.bytes_('')
assert_equal(pickle.loads(
pickle.dumps(test_string, protocol=proto)), test_string)
@@ -2350,7 +2344,7 @@ class TestRegression:
values = {
np.void: b"a",
np.bytes_: b"a",
- np.unicode_: "a",
+ np.str_: "a",
np.datetime64: "2017-08-25",
}
for sctype in scalar_types:
@@ -2557,3 +2551,14 @@ class TestRegression:
f"Unexpected types order of ufunc in {operation}"
f"for {order}. Possible fix: Use signed before unsigned"
"in generate_umath.py")
+
+ def test_nonbool_logical(self):
+ # gh-22845
+ # create two arrays with bit patterns that do not overlap.
+ # needs to be large enough to test both SIMD and scalar paths
+ size = 100
+ a = np.frombuffer(b'\x01' * size, dtype=np.bool_)
+ b = np.frombuffer(b'\x80' * size, dtype=np.bool_)
+ expected = np.ones(size, dtype=np.bool_)
+ assert_array_equal(np.logical_and(a, b), expected)
+