summaryrefslogtreecommitdiff
path: root/numpy/lib/arraysetops.py
diff options
context:
space:
mode:
authorMilesCranmer <miles.cranmer@gmail.com>2022-06-17 12:37:53 -0400
committerMilesCranmer <miles.cranmer@gmail.com>2022-06-17 12:37:53 -0400
commitc5db8e86ebdcb54e33c93386a18b86615789fc50 (patch)
tree1122a51dda244c4e5219238cf778dca2dded772b /numpy/lib/arraysetops.py
parent8f5764447cdf6f8ab21ba0f863c65a8d7a7728b5 (diff)
downloadnumpy-c5db8e86ebdcb54e33c93386a18b86615789fc50.tar.gz
MAINT: Protect against integer overflow in in1d
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r--numpy/lib/arraysetops.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py
index bc25743f7..a67472a22 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -652,11 +652,14 @@ def in1d(ar1, ar2, assume_unique=False, invert=False, kind=None):
below_memory_constraint = (
ar2_range <= 6 * (ar1_size + ar2_size)
)
+ range_safe_from_overflow = True
except FloatingPointError:
- below_memory_constraint = False
+ range_safe_from_overflow = False
- # Use the fast integer algorithm
- if below_memory_constraint or kind == 'dictionary':
+ if (
+ range_safe_from_overflow and
+ (below_memory_constraint or kind == 'dictionary')
+ ):
if invert:
outgoing_array = np.ones_like(ar1, dtype=bool)