summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarren Weckesser <warren.weckesser@gmail.com>2020-03-13 16:25:06 -0400
committerWarren Weckesser <warren.weckesser@gmail.com>2020-03-15 11:35:39 -0400
commit30689433982597fa89f7f27fcf031ec77eec250a (patch)
tree67863603471ccc6645ec62c52a9f0b3e9833316f
parentd18156b00d4215d869d71f1d4c7d66037bd50b4b (diff)
downloadnumpy-30689433982597fa89f7f27fcf031ec77eec250a.tar.gz
MAINT: lib: PEP-8 clean up in test_arraysetops.py.
-rw-r--r--numpy/lib/tests/test_arraysetops.py79
1 files changed, 41 insertions, 38 deletions
diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py
index babc4e439..81ba789e3 100644
--- a/numpy/lib/tests/test_arraysetops.py
+++ b/numpy/lib/tests/test_arraysetops.py
@@ -11,7 +11,6 @@ from numpy.lib.arraysetops import (
import pytest
-
class TestSetOps:
def test_intersect1d(self):
@@ -118,12 +117,13 @@ class TestSetOps:
assert_array_equal([-1, 0], ediff1d(zero_elem, to_begin=-1, to_end=0))
assert_array_equal([], ediff1d(one_elem))
assert_array_equal([1], ediff1d(two_elem))
- assert_array_equal([7,1,9], ediff1d(two_elem, to_begin=7, to_end=9))
- assert_array_equal([5,6,1,7,8], ediff1d(two_elem, to_begin=[5,6], to_end=[7,8]))
- assert_array_equal([1,9], ediff1d(two_elem, to_end=9))
- assert_array_equal([1,7,8], ediff1d(two_elem, to_end=[7,8]))
- assert_array_equal([7,1], ediff1d(two_elem, to_begin=7))
- assert_array_equal([5,6,1], ediff1d(two_elem, to_begin=[5,6]))
+ assert_array_equal([7, 1, 9], ediff1d(two_elem, to_begin=7, to_end=9))
+ assert_array_equal([5, 6, 1, 7, 8],
+ ediff1d(two_elem, to_begin=[5, 6], to_end=[7, 8]))
+ assert_array_equal([1, 9], ediff1d(two_elem, to_end=9))
+ assert_array_equal([1, 7, 8], ediff1d(two_elem, to_end=[7, 8]))
+ assert_array_equal([7, 1], ediff1d(two_elem, to_begin=7))
+ assert_array_equal([5, 6, 1], ediff1d(two_elem, to_begin=[5, 6]))
@pytest.mark.parametrize("ary, prepend, append", [
# should fail because trying to cast
@@ -156,27 +156,27 @@ class TestSetOps:
to_end=append,
to_begin=prepend)
- @pytest.mark.parametrize("ary,"
- "prepend,"
- "append,"
- "expected", [
- (np.array([1, 2, 3], dtype=np.int16),
- 2**16, # will be cast to int16 under same kind rule.
- 2**16 + 4,
- np.array([0, 1, 1, 4], dtype=np.int16)),
- (np.array([1, 2, 3], dtype=np.float32),
- np.array([5], dtype=np.float64),
- None,
- np.array([5, 1, 1], dtype=np.float32)),
- (np.array([1, 2, 3], dtype=np.int32),
- 0,
- 0,
- np.array([0, 1, 1, 0], dtype=np.int32)),
- (np.array([1, 2, 3], dtype=np.int64),
- 3,
- -9,
- np.array([3, 1, 1, -9], dtype=np.int64)),
- ])
+ @pytest.mark.parametrize(
+ "ary,prepend,append,expected",
+ [
+ (np.array([1, 2, 3], dtype=np.int16),
+ 2**16, # will be cast to int16 under same kind rule.
+ 2**16 + 4,
+ np.array([0, 1, 1, 4], dtype=np.int16)),
+ (np.array([1, 2, 3], dtype=np.float32),
+ np.array([5], dtype=np.float64),
+ None,
+ np.array([5, 1, 1], dtype=np.float32)),
+ (np.array([1, 2, 3], dtype=np.int32),
+ 0,
+ 0,
+ np.array([0, 1, 1, 0], dtype=np.int32)),
+ (np.array([1, 2, 3], dtype=np.int64),
+ 3,
+ -9,
+ np.array([3, 1, 1, -9], dtype=np.int64)),
+ ]
+ )
def test_ediff1d_scalar_handling(self,
ary,
prepend,
@@ -191,7 +191,6 @@ class TestSetOps:
assert_equal(actual, expected)
assert actual.dtype == expected.dtype
-
def test_isin(self):
# the tests for in1d cover most of isin's behavior
# if in1d is removed, would need to change those tests to test
@@ -200,33 +199,34 @@ class TestSetOps:
b = np.asarray(b).flatten().tolist()
return a in b
isin_slow = np.vectorize(_isin_slow, otypes=[bool], excluded={1})
+
def assert_isin_equal(a, b):
x = isin(a, b)
y = isin_slow(a, b)
assert_array_equal(x, y)
- #multidimensional arrays in both arguments
+ # multidimensional arrays in both arguments
a = np.arange(24).reshape([2, 3, 4])
b = np.array([[10, 20, 30], [0, 1, 3], [11, 22, 33]])
assert_isin_equal(a, b)
- #array-likes as both arguments
+ # array-likes as both arguments
c = [(9, 8), (7, 6)]
d = (9, 7)
assert_isin_equal(c, d)
- #zero-d array:
+ # zero-d array:
f = np.array(3)
assert_isin_equal(f, b)
assert_isin_equal(a, f)
assert_isin_equal(f, f)
- #scalar:
+ # scalar:
assert_isin_equal(5, b)
assert_isin_equal(a, 6)
assert_isin_equal(5, 6)
- #empty array-like:
+ # empty array-like:
x = []
assert_isin_equal(x, b)
assert_isin_equal(a, x)
@@ -520,7 +520,8 @@ class TestUnique:
a = []
a1_idx = np.unique(a, return_index=True)[1]
a2_inv = np.unique(a, return_inverse=True)[1]
- a3_idx, a3_inv = np.unique(a, return_index=True, return_inverse=True)[1:]
+ a3_idx, a3_inv = np.unique(a, return_index=True,
+ return_inverse=True)[1:]
assert_equal(a1_idx.dtype, np.intp)
assert_equal(a2_inv.dtype, np.intp)
assert_equal(a3_idx.dtype, np.intp)
@@ -602,11 +603,13 @@ class TestUnique:
else:
expected_shape[axis] = 1
- assert_array_equal(unique(multiple_zeros, axis=axis), np.empty(shape=expected_shape))
+ assert_array_equal(unique(multiple_zeros, axis=axis),
+ np.empty(shape=expected_shape))
def test_unique_masked(self):
# issue 8664
- x = np.array([64, 0, 1, 2, 3, 63, 63, 0, 0, 0, 1, 2, 0, 63, 0], dtype='uint8')
+ x = np.array([64, 0, 1, 2, 3, 63, 63, 0, 0, 0, 1, 2, 0, 63, 0],
+ dtype='uint8')
y = np.ma.masked_equal(x, 0)
v = np.unique(y)
@@ -621,7 +624,7 @@ class TestUnique:
# as unsigned byte strings. See gh-10495.
fmt = "sort order incorrect for integer type '%s'"
for dt in 'bhilq':
- a = np.array([[-1],[0]], dt)
+ a = np.array([[-1], [0]], dt)
b = np.unique(a, axis=0)
assert_array_equal(a, b, fmt % dt)