diff options
author | Miles Cranmer <miles.cranmer@gmail.com> | 2022-06-24 08:24:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-24 05:24:22 -0700 |
commit | 019c8c9b2a7c084eb01cf4d8569799a5537d884d (patch) | |
tree | c67886867700838eba5d4f821ef6380047f834a8 /numpy/lib/tests/test_arraysetops.py | |
parent | 3039cd3a98c0ef7b1cc11b4ad6a844f4c049098b (diff) | |
download | numpy-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/tests/test_arraysetops.py')
-rw-r--r-- | numpy/lib/tests/test_arraysetops.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py index d91d36282..a21e5f640 100644 --- a/numpy/lib/tests/test_arraysetops.py +++ b/numpy/lib/tests/test_arraysetops.py @@ -232,12 +232,30 @@ class TestSetOps: assert_isin_equal(5, 6) # empty array-like: - if kind in {None, "sort"}: + if kind != "table": + # An empty list will become float64, + # which is invalid for kind="table" x = [] assert_isin_equal(x, b) assert_isin_equal(a, x) assert_isin_equal(x, x) + # empty array with various types: + for dtype in [bool, np.int64, np.float64]: + if kind == "table" and dtype == np.float64: + continue + + if dtype in {np.int64, np.float64}: + ar = np.array([10, 20, 30], dtype=dtype) + elif dtype in {bool}: + ar = np.array([True, False, False]) + + empty_array = np.array([], dtype=dtype) + + assert_isin_equal(empty_array, ar) + assert_isin_equal(ar, empty_array) + assert_isin_equal(empty_array, empty_array) + @pytest.mark.parametrize("kind", [None, "sort", "table"]) def test_in1d(self, kind): # we use two different sizes for the b array here to test the |