From b2099b04f9bbdc1135e0b538db6f287130001d28 Mon Sep 17 00:00:00 2001 From: moink Date: Thu, 31 Dec 2020 13:09:54 +0100 Subject: [PATCH 1/5] TST: GH30999 address all bare pytest.raises in pandas/tests/arrays/boolean/test_arithmetic.py --- .../tests/arrays/boolean/test_arithmetic.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index 01de64568a011..cfd25c3dae876 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -1,4 +1,5 @@ import operator +import re import numpy as np import pytest @@ -46,7 +47,7 @@ def test_add_mul(left_array, right_array, opname, exp): def test_sub(left_array, right_array): - with pytest.raises(TypeError): + with tm.external_error_raised(TypeError): # numpy points to ^ operator or logical_xor function instead left_array - right_array @@ -92,13 +93,24 @@ def test_error_invalid_values(data, all_arithmetic_operators): ops = getattr(s, op) # invalid scalars - with pytest.raises(TypeError): + msg = ( + "did not contain a loop with signature matching types|" + "BooleanArray cannot perform the operation|" + "not supported for the input types, and the inputs could not be safely coerced " + "to any supported types according to the casting rule ''safe''" + ) + with pytest.raises(TypeError, match=msg): ops("foo") - with pytest.raises(TypeError): + msg = re.escape("unsupported operand type(s) for") + with pytest.raises(TypeError, match=msg): ops(pd.Timestamp("20180101")) # invalid array-likes if op not in ("__mul__", "__rmul__"): # TODO(extension) numpy's mul with object array sees booleans as numbers - with pytest.raises(TypeError): + msg = ( + r"unsupported operand type\(s\) for|can only concatenate str|" + "not all arguments converted during string formatting" + ) + with pytest.raises(TypeError, match=msg): ops(pd.Series("foo", index=s.index)) From 7d14cdcc89e4a8908c230c7c9115f6a0981c2420 Mon Sep 17 00:00:00 2001 From: moink Date: Thu, 31 Dec 2020 17:50:18 +0100 Subject: [PATCH 2/5] TST: GH30999 attempt to fix CI failure --- pandas/tests/arrays/boolean/test_arithmetic.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index cfd25c3dae876..6bf035a69849a 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -1,5 +1,4 @@ import operator -import re import numpy as np import pytest @@ -101,7 +100,10 @@ def test_error_invalid_values(data, all_arithmetic_operators): ) with pytest.raises(TypeError, match=msg): ops("foo") - msg = re.escape("unsupported operand type(s) for") + msg = ( + r"unsupported operand type\(s\) for|" + "Concatenation operation is not implemented for NumPy arrays" + ) with pytest.raises(TypeError, match=msg): ops(pd.Timestamp("20180101")) @@ -110,7 +112,7 @@ def test_error_invalid_values(data, all_arithmetic_operators): # TODO(extension) numpy's mul with object array sees booleans as numbers msg = ( r"unsupported operand type\(s\) for|can only concatenate str|" - "not all arguments converted during string formatting" + "not all arguments converted during string formatting|" ) with pytest.raises(TypeError, match=msg): ops(pd.Series("foo", index=s.index)) From bbd2316975bb919867f0e0befbca765085f159c9 Mon Sep 17 00:00:00 2001 From: moink Date: Thu, 31 Dec 2020 20:31:49 +0100 Subject: [PATCH 3/5] TST: GH30999 change test_sub back to pytest.raises --- pandas/tests/arrays/boolean/test_arithmetic.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index 6bf035a69849a..4d31491d1ecf9 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -1,4 +1,5 @@ import operator +import re import numpy as np import pytest @@ -46,8 +47,11 @@ def test_add_mul(left_array, right_array, opname, exp): def test_sub(left_array, right_array): - with tm.external_error_raised(TypeError): - # numpy points to ^ operator or logical_xor function instead + msg = re.escape( + "numpy boolean subtract, the `-` operator, is not supported, " + "use the bitwise_xor, the `^` operator, or the logical_xor function instead." + ) + with pytest.raises(TypeError, match=msg): left_array - right_array From 8c8e9578bdbce207494bc9ca3882f10cde6e12ae Mon Sep 17 00:00:00 2001 From: moink Date: Thu, 31 Dec 2020 20:33:45 +0100 Subject: [PATCH 4/5] TST: GH30999 rm extra pipe character --- pandas/tests/arrays/boolean/test_arithmetic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index 4d31491d1ecf9..ae3149adc9d39 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -116,7 +116,7 @@ def test_error_invalid_values(data, all_arithmetic_operators): # TODO(extension) numpy's mul with object array sees booleans as numbers msg = ( r"unsupported operand type\(s\) for|can only concatenate str|" - "not all arguments converted during string formatting|" + "not all arguments converted during string formatting" ) with pytest.raises(TypeError, match=msg): ops(pd.Series("foo", index=s.index)) From 9a7be53827a8e9b887096b6b6f5fd7b54fdb0fac Mon Sep 17 00:00:00 2001 From: moink Date: Thu, 31 Dec 2020 21:38:30 +0100 Subject: [PATCH 5/5] TST: GH30999 fix message for earlier versions of numpy that say "deprecated" instead of "not supported" --- pandas/tests/arrays/boolean/test_arithmetic.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index ae3149adc9d39..f8f1af4c3da51 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -1,5 +1,4 @@ import operator -import re import numpy as np import pytest @@ -47,9 +46,9 @@ def test_add_mul(left_array, right_array, opname, exp): def test_sub(left_array, right_array): - msg = re.escape( - "numpy boolean subtract, the `-` operator, is not supported, " - "use the bitwise_xor, the `^` operator, or the logical_xor function instead." + msg = ( + r"numpy boolean subtract, the `-` operator, is (?:deprecated|not supported), " + r"use the bitwise_xor, the `\^` operator, or the logical_xor function instead\." ) with pytest.raises(TypeError, match=msg): left_array - right_array