summaryrefslogtreecommitdiff
path: root/numpy/ma/tests/test_extras.py
diff options
context:
space:
mode:
authorB R S Recht <brsr@users.noreply.github.com>2017-05-04 20:03:09 -0400
committerEric Wieser <wieser.eric@gmail.com>2017-05-05 01:03:09 +0100
commit69b0c42bca27dd5d5522de306bcd7db7deccbfad (patch)
treeb857fc11775a3633bf959a158f5d6be3e7ef7971 /numpy/ma/tests/test_extras.py
parent1d592c12ca7f9c7f471aa8d20b538c5cb4f2cdce (diff)
downloadpython-numpy-69b0c42bca27dd5d5522de306bcd7db7deccbfad.tar.gz
python-numpy-69b0c42bca27dd5d5522de306bcd7db7deccbfad.tar.bz2
python-numpy-69b0c42bca27dd5d5522de306bcd7db7deccbfad.zip
ENH: Add isin, genereralizing in1d to ND arrays (#8423)
This fixes gh-8331 Also update the docs for arraysetops to remove the outdated "1D" from the description, which was already incorrect for np.unique.
Diffstat (limited to 'numpy/ma/tests/test_extras.py')
-rw-r--r--numpy/ma/tests/test_extras.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/numpy/ma/tests/test_extras.py b/numpy/ma/tests/test_extras.py
index 77a5c0fc6..e7ebd8b82 100644
--- a/numpy/ma/tests/test_extras.py
+++ b/numpy/ma/tests/test_extras.py
@@ -28,7 +28,7 @@ from numpy.ma.extras import (
median, average, unique, setxor1d, setdiff1d, union1d, intersect1d, in1d,
ediff1d, apply_over_axes, apply_along_axis, compress_nd, compress_rowcols,
mask_rowcols, clump_masked, clump_unmasked, flatnotmasked_contiguous,
- notmasked_contiguous, notmasked_edges, masked_all, masked_all_like,
+ notmasked_contiguous, notmasked_edges, masked_all, masked_all_like, isin,
diagflat
)
import numpy.ma.extras as mae
@@ -1435,6 +1435,27 @@ class TestArraySetOps(TestCase):
#
assert_array_equal([], setxor1d([], []))
+ 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
+ # isin instead.
+ a = np.arange(24).reshape([2, 3, 4])
+ mask = np.zeros([2, 3, 4])
+ mask[1, 2, 0] = 1
+ a = array(a, mask=mask)
+ b = array(data=[0, 10, 20, 30, 1, 3, 11, 22, 33],
+ mask=[0, 1, 0, 1, 0, 1, 0, 1, 0])
+ ec = zeros((2, 3, 4), dtype=bool)
+ ec[0, 0, 0] = True
+ ec[0, 0, 1] = True
+ ec[0, 2, 3] = True
+ c = isin(a, b)
+ assert_(isinstance(c, MaskedArray))
+ assert_array_equal(c, ec)
+ #compare results of np.isin to ma.isin
+ d = np.isin(a, b[~b.mask]) & ~a.mask
+ assert_array_equal(c, d)
+
def test_in1d(self):
# Test in1d
a = array([1, 2, 5, 7, -1], mask=[0, 0, 0, 0, 1])