summaryrefslogtreecommitdiff
path: root/numpy/lib/arraysetops.py
diff options
context:
space:
mode:
authorJörg Döpfert <jdoepfert@users.noreply.github.com>2017-11-18 19:21:23 +0100
committerEric Wieser <wieser.eric@gmail.com>2017-11-18 10:21:23 -0800
commit2d140f11857fc1353d6b2dcbb801e693128fd09a (patch)
treee2b7b9edcbcc07de412e357198593fec333635aa /numpy/lib/arraysetops.py
parentc41961313e7ddab6563bd82a51ee512a5c44e785 (diff)
downloadnumpy-2d140f11857fc1353d6b2dcbb801e693128fd09a.tar.gz
ENH: Make `np.in1d()` work for unorderable object arrays (#9999)
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r--numpy/lib/arraysetops.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py
index ededb9dd0..f3301af92 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -448,8 +448,14 @@ def in1d(ar1, ar2, assume_unique=False, invert=False):
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:
+ # Check if one of the arrays may contain arbitrary objects
+ contains_object = ar1.dtype.hasobject or ar2.dtype.hasobject
+
+ # This code is run when
+ # a) the first condition is true, making the code significantly faster
+ # b) the second condition is true (i.e. `ar1` or `ar2` may contain
+ # arbitrary objects), since then sorting is not guaranteed to work
+ if len(ar2) < 10 * len(ar1) ** 0.145 or contains_object:
if invert:
mask = np.ones(len(ar1), dtype=bool)
for a in ar2: