From b1bb9dac66bb885fecbfb8348b940e859992386b Mon Sep 17 00:00:00 2001 From: Yanxian Lin Date: Thu, 10 Sep 2020 23:00:27 -0700 Subject: [PATCH 1/2] TST: #31922 assert no segmentation fault with numpy.array.__contains__ --- pandas/tests/scalar/test_na_scalar.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pandas/tests/scalar/test_na_scalar.py b/pandas/tests/scalar/test_na_scalar.py index 0a7dfbee4e672..ca373e8b6c333 100644 --- a/pandas/tests/scalar/test_na_scalar.py +++ b/pandas/tests/scalar/test_na_scalar.py @@ -305,3 +305,17 @@ def test_pickle_roundtrip_containers(as_frame, values, dtype): s = s.to_frame(name="A") result = tm.round_trip_pickle(s) tm.assert_equal(result, s) + + +def test_np_array_contains_na(): + # GH 31922 + msg = "boolean value of NA is ambiguous" + with pytest.raises(TypeError, match=msg): + NA in np.array(["a"], dtype=object) + + +def test_list_contains_na(): + # GH 31922 + msg = "boolean value of NA is ambiguous" + with pytest.raises(TypeError, match=msg): + NA in ["a"] From e009d619f6450629c8243e9b2ecb73a50a685936 Mon Sep 17 00:00:00 2001 From: Yanxian Lin Date: Fri, 11 Sep 2020 11:54:37 -0700 Subject: [PATCH 2/2] TST: assert no segmentation fault with numpy.array.__contains__ (#31922) --- pandas/tests/scalar/test_na_scalar.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/pandas/tests/scalar/test_na_scalar.py b/pandas/tests/scalar/test_na_scalar.py index ca373e8b6c333..fefd3fafafe7c 100644 --- a/pandas/tests/scalar/test_na_scalar.py +++ b/pandas/tests/scalar/test_na_scalar.py @@ -307,15 +307,9 @@ def test_pickle_roundtrip_containers(as_frame, values, dtype): tm.assert_equal(result, s) -def test_np_array_contains_na(): +@pytest.mark.parametrize("array", [np.array(["a"], dtype=object), ["a"]]) +def test_array_contains_na(array): # GH 31922 msg = "boolean value of NA is ambiguous" with pytest.raises(TypeError, match=msg): - NA in np.array(["a"], dtype=object) - - -def test_list_contains_na(): - # GH 31922 - msg = "boolean value of NA is ambiguous" - with pytest.raises(TypeError, match=msg): - NA in ["a"] + NA in array