summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornjsmith <njs@pobox.com>2012-12-21 05:01:47 -0800
committernjsmith <njs@pobox.com>2012-12-21 05:01:47 -0800
commit3abd8699dc3c71e389356ca6d80a2cb9efa16151 (patch)
tree8ebd6d30f8bd13b1cee0df2762b96ff26bbdee05
parentc9325530b499f205b46d444d2f00be1bc49c9e23 (diff)
parentb0ac985036918c39322e18d06bd69523cfef9e39 (diff)
downloadnumpy-3abd8699dc3c71e389356ca6d80a2cb9efa16151.tar.gz
Merge pull request #2800 from seberg/issue2755
BUG: Fix regression for in1d with non-array input
-rw-r--r--numpy/lib/arraysetops.py4
-rw-r--r--numpy/lib/tests/test_arraysetops.py18
2 files changed, 20 insertions, 2 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py
index 20a0e7151..ae14970e2 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -324,6 +324,10 @@ def in1d(ar1, ar2, assume_unique=False):
array([0, 2, 0])
"""
+ # Ravel both arrays, behavior for the first array could be different
+ ar1 = np.asarray(ar1).ravel()
+ ar2 = np.asarray(ar2).ravel()
+
# This code is significantly faster when the condition is satisfied.
if len(ar2) < 10 * len(ar1) ** 0.145:
mask = np.zeros(len(ar1), dtype=np.bool)
diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py
index b0d2ca7c3..5f4f10c76 100644
--- a/numpy/lib/tests/test_arraysetops.py
+++ b/numpy/lib/tests/test_arraysetops.py
@@ -124,8 +124,9 @@ class TestSetOps(TestCase):
# we use two different sizes for the b array here to test the
# two different paths in in1d().
for mult in (1, 10):
- a = np.array([5, 7, 1, 2])
- b = np.array([2, 4, 3, 1, 5] * mult)
+ # One check without np.array, to make sure lists are handled correct
+ a = [5, 7, 1, 2]
+ b = [2, 4, 3, 1, 5] * mult
ec = np.array([True, False, True, True])
c = in1d(a, b, assume_unique=True)
assert_array_equal(c, ec)
@@ -188,6 +189,19 @@ class TestSetOps(TestCase):
assert_array_equal(c, ec)
+ def test_in1d_ravel(self):
+ # Test that in1d ravels its input arrays. This is not documented
+ # behavior however. The test is to ensure consistentency.
+ a = np.arange(6).reshape(2,3)
+ b = np.arange(3,9).reshape(3,2)
+ long_b = np.arange(3, 63).reshape(30,2)
+ ec = np.array([False, False, False, True, True, True])
+
+ assert_array_equal(in1d(a, b, assume_unique=True), ec)
+ assert_array_equal(in1d(a, b, assume_unique=False), ec)
+ assert_array_equal(in1d(a, long_b, assume_unique=True), ec)
+ assert_array_equal(in1d(a, long_b, assume_unique=False), ec)
+
def test_union1d( self ):
a = np.array( [5, 4, 7, 1, 2] )
b = np.array( [2, 4, 3, 3, 2, 1, 5] )