From 54aa5bced8a0f934dbb3cf89fd2fd37c2c792afb Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 23 Dec 2022 11:21:30 -0500 Subject: [PATCH] TST: Mixed integer types for in1d --- numpy/lib/tests/test_arraysetops.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py index bb07e25a954b..df82706fb771 100644 --- a/numpy/lib/tests/test_arraysetops.py +++ b/numpy/lib/tests/test_arraysetops.py @@ -414,6 +414,30 @@ def test_in1d_table_timedelta_fails(self): with pytest.raises(ValueError): in1d(a, b, kind="table") + @pytest.mark.parametrize( + "dtype1,dtype2", + [ + (np.int8, np.int16), + (np.int16, np.int8), + (np.uint8, np.uint16), + (np.uint16, np.uint8), + (np.uint8, np.int16), + (np.int16, np.uint8), + ] + ) + def test_in1d_mixed_dtype(self, dtype1, dtype2): + """Test that in1d works as expected for mixed dtype input.""" + is_dtype2_signed = np.issubdtype(dtype2, np.signedinteger) + ar1 = np.array([0, 0, 1, 1], dtype=dtype1) + + if is_dtype2_signed: + ar2 = np.array([-128, 0, 127], dtype=dtype2) + else: + ar2 = np.array([127, 0, 255], dtype=dtype2) + + expected = np.array([True, True, False, False]) + assert_array_equal(in1d(ar1, ar2), expected) + @pytest.mark.parametrize("kind", [None, "sort", "table"]) def test_in1d_mixed_boolean(self, kind): """Test that in1d works as expected for bool/int input."""