summaryrefslogtreecommitdiff
path: root/numpy/lib/arraysetops.py
diff options
context:
space:
mode:
authorMiles Cranmer <miles.cranmer@gmail.com>2022-06-24 08:24:22 -0400
committerGitHub <noreply@github.com>2022-06-24 05:24:22 -0700
commit019c8c9b2a7c084eb01cf4d8569799a5537d884d (patch)
treec67886867700838eba5d4f821ef6380047f834a8 /numpy/lib/arraysetops.py
parent3039cd3a98c0ef7b1cc11b4ad6a844f4c049098b (diff)
downloadnumpy-019c8c9b2a7c084eb01cf4d8569799a5537d884d.tar.gz
BUG: Fix in1d for empty integer array as input (#21842)
* TST: Tests empty input to in1d of various types * MAINT: Skip table method on empty input array * MAINT: Check array size before call to min * MAINT: Return early for kind="table" and empty ar2 * TST: Test other dtypes of empty arrays
Diffstat (limited to 'numpy/lib/arraysetops.py')
-rw-r--r--numpy/lib/arraysetops.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/numpy/lib/arraysetops.py b/numpy/lib/arraysetops.py
index 9a44d7e44..fa332e7fd 100644
--- a/numpy/lib/arraysetops.py
+++ b/numpy/lib/arraysetops.py
@@ -636,6 +636,13 @@ def in1d(ar1, ar2, assume_unique=False, invert=False, *, kind=None):
f"Invalid kind: '{kind}'. Please use None, 'sort' or 'table'.")
if integer_arrays and kind in {None, 'table'}:
+
+ if ar2.size == 0:
+ if invert:
+ return np.ones_like(ar1, dtype=bool)
+ else:
+ return np.zeros_like(ar1, dtype=bool)
+
ar2_min = np.min(ar2)
ar2_max = np.max(ar2)