summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2019-11-04 17:32:10 -0700
committerGitHub <noreply@github.com>2019-11-04 17:32:10 -0700
commit4393e0c0cb1772d0f9691117d238d000b209decd (patch)
tree5dda9c9a885af59ecdcd4c3c947e69bd6bab48bf /numpy/lib
parent7b8513fff4c3673d8a967a1d72a73feab2072e8f (diff)
parent9aa8c4756d7282dd49a7093ce7a6725258106b9a (diff)
downloadnumpy-4393e0c0cb1772d0f9691117d238d000b209decd.tar.gz
Merge pull request #14800 from mattip/reorder-obj-comparison-loop
ENH: change object-array comparisons to prefer OO->O unfuncs
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/arraysetops.py8
-rw-r--r--numpy/lib/nanfunctions.py2
2 files changed, 7 insertions, 3 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py
index 2309f7e42..cf45e181b 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -562,11 +562,15 @@ def in1d(ar1, ar2, assume_unique=False, invert=False):
if invert:
mask = np.ones(len(ar1), dtype=bool)
for a in ar2:
- mask &= (ar1 != a)
+ # convert object arrays to bool
+ # cannot use np.not_equal until 'S' and 'U' have loops
+ mask &= (ar1 != a).astype(bool)
else:
mask = np.zeros(len(ar1), dtype=bool)
for a in ar2:
- mask |= (ar1 == a)
+ # convert object arrays to bool
+ # cannot use np.equal until 'S' and 'U' have loops
+ mask |= (ar1 == a).astype(bool)
return mask
# Otherwise use sorting
diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py
index 18ccab3b8..457cca146 100644
--- a/numpy/lib/nanfunctions.py
+++ b/numpy/lib/nanfunctions.py
@@ -99,7 +99,7 @@ def _replace_nan(a, val):
if a.dtype == np.object_:
# object arrays do not support `isnan` (gh-9009), so make a guess
- mask = a != a
+ mask = np.not_equal(a, a, dtype=bool)
elif issubclass(a.dtype.type, np.inexact):
mask = np.isnan(a)
else: