From a0e8acc9485276fd1f24028fc1d15b96acb0f8d7 Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 18:53:02 -0700 Subject: [PATCH 01/14] test_assert_series_equal.py --- pandas/tests/util/test_assert_series_equal.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pandas/tests/util/test_assert_series_equal.py b/pandas/tests/util/test_assert_series_equal.py index ae4523014b01d..6bf461d849b5e 100644 --- a/pandas/tests/util/test_assert_series_equal.py +++ b/pandas/tests/util/test_assert_series_equal.py @@ -292,9 +292,22 @@ def test_series_equal_exact_for_nonnumeric(): tm.assert_series_equal(s1, s2, check_exact=True) tm.assert_series_equal(s2, s1, check_exact=True) - with pytest.raises(AssertionError): + msg = """Series are different + +Series values are different \\(100\\.0 %\\) +\\[index\\]: \\[0, 1\\] +\\[left\\]: \\[a, b\\] +\\[right\\]: \\[b, a\\]""" + with pytest.raises(AssertionError, match=msg): tm.assert_series_equal(s1, s3, check_exact=True) - with pytest.raises(AssertionError): + + msg = """Series are different + +Series values are different \\(100\\.0 %\\) +\\[index\\]: \\[0, 1\\] +\\[left\\]: \\[b, a\\] +\\[right\\]: \\[a, b\\]""" + with pytest.raises(AssertionError, match=msg): tm.assert_series_equal(s3, s1, check_exact=True) From f840032edcaa85d9cb510bc585b74e2734ef3322 Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 19:54:59 -0700 Subject: [PATCH 02/14] test_setitem_slice_mismatch_length_raises --- pandas/tests/extension/base/setitem.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pandas/tests/extension/base/setitem.py b/pandas/tests/extension/base/setitem.py index a4e6fc0f78cbb..6df6acccb56c6 100644 --- a/pandas/tests/extension/base/setitem.py +++ b/pandas/tests/extension/base/setitem.py @@ -282,8 +282,23 @@ def test_setitem_loc_iloc_slice(self, data): self.assert_equal(result, expected) def test_setitem_slice_mismatch_length_raises(self, data): + # This class is a test mixin class, based on which test class it's mixed with the expected error messages can + # vary. This regular expression catches all the variants of those messages. It's formatted as a big OR + # statement: /m1|m2|m3|m4/ + + msg = ( + # pandas.core.arrays.period.PeriodArray + # pandas.core.arrays.datetimes.DatetimeArray + "(cannot set using a slice indexer with a different length than the value)" "|" + # string_arrow.ArrowStringArray + "(Length of indexer and values mismatch)" "|" + # pandas.tests.extension.decimal.array.DecimalArray + "(cannot copy sequence with size \\d to array axis with dimension \\d)" "|" + # All the rest + "(could not broadcast input array from shape \\(\\d\\) into shape \\(\\d\\))" + ) arr = data[:5] - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): arr[:1] = arr[:2] def test_setitem_slice_array(self, data): From 8c1c26d833635abd7898b97622e7173a3f9ad9d3 Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 20:02:05 -0700 Subject: [PATCH 03/14] test_setitem_scalar_key_sequence_raise --- pandas/tests/extension/base/setitem.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pandas/tests/extension/base/setitem.py b/pandas/tests/extension/base/setitem.py index 6df6acccb56c6..f3560c37ab17e 100644 --- a/pandas/tests/extension/base/setitem.py +++ b/pandas/tests/extension/base/setitem.py @@ -307,8 +307,17 @@ def test_setitem_slice_array(self, data): self.assert_extension_array_equal(arr, data[-5:]) def test_setitem_scalar_key_sequence_raise(self, data): + # Check the comment on test_setitem_slice_mismatch_length_raises for more info. + msg = ( + # pandas.core.arrays.string_arrow.ArrowStringArray + "(Must pass scalars with scalar indexer)" "|" + # pandas.core.arrays.datetimes.DatetimeArray + "(Could not convert object to NumPy datetime)" "|" + # All the rest + "(setting an array element with a sequence)" + ) arr = data[:5].copy() - with pytest.raises(ValueError): + with pytest.raises(ValueError, match=msg): arr[0] = arr[[0, 1]] def test_setitem_preserves_views(self, data): From 0fa645177e0dfd87739ec7b6623b2cd2bed485c2 Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 20:13:03 -0700 Subject: [PATCH 04/14] test_sub --- pandas/tests/arrays/boolean/test_arithmetic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index 01de64568a011..aec6023392e50 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -46,7 +46,8 @@ def test_add_mul(left_array, right_array, opname, exp): def test_sub(left_array, right_array): - with pytest.raises(TypeError): + msg = "the `-` operator, is not supported, use the bitwise_xor, the `\\^` operator, or the logical_xor" + with pytest.raises(TypeError, match=msg): # numpy points to ^ operator or logical_xor function instead left_array - right_array From 712b479adcfd5ad894a50c30029c73c33eecbd00 Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 20:22:14 -0700 Subject: [PATCH 05/14] test_arithmetic --- .../tests/arrays/boolean/test_arithmetic.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index aec6023392e50..e77ff42ae76c6 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -93,13 +93,26 @@ def test_error_invalid_values(data, all_arithmetic_operators): ops = getattr(s, op) # invalid scalars - with pytest.raises(TypeError): + msg = ( + "(ufunc '\\w+' did not contain a loop with signature matching types)" "|" + "(ufunc '\\w+' not supported for the input types, and the inputs could " + "not be safely coerced to any supported types)" "|" + "(\\w+ cannot perform the operation \\w+)" + ) + with pytest.raises(TypeError, match=msg): ops("foo") - with pytest.raises(TypeError): + + msg = "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 = ( + "(unsupported operand type\\(s\\) for)" "|" + "(can only concatenate str \\(not \"bool\"\\) to str)" "|" + "(not all arguments converted during string formatting)" "|" + ) + with pytest.raises(TypeError, match=msg): ops(pd.Series("foo", index=s.index)) From 1ecbdf134a251b1e2a11f99402bb0f9c3ad5c809 Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 20:23:38 -0700 Subject: [PATCH 06/14] black pandas on test_arithmetic.py --- pandas/tests/arrays/boolean/test_arithmetic.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index e77ff42ae76c6..3dbc3f6a7dd8d 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -94,9 +94,9 @@ def test_error_invalid_values(data, all_arithmetic_operators): # invalid scalars msg = ( - "(ufunc '\\w+' did not contain a loop with signature matching types)" "|" + "(ufunc '\\w+' did not contain a loop with signature matching types)|" "(ufunc '\\w+' not supported for the input types, and the inputs could " - "not be safely coerced to any supported types)" "|" + "not be safely coerced to any supported types)|" "(\\w+ cannot perform the operation \\w+)" ) with pytest.raises(TypeError, match=msg): @@ -110,9 +110,9 @@ def test_error_invalid_values(data, all_arithmetic_operators): if op not in ("__mul__", "__rmul__"): # TODO(extension) numpy's mul with object array sees booleans as numbers msg = ( - "(unsupported operand type\\(s\\) for)" "|" - "(can only concatenate str \\(not \"bool\"\\) to str)" "|" - "(not all arguments converted during string formatting)" "|" + "(unsupported operand type\\(s\\) for)|" + '(can only concatenate str \\(not "bool"\\) to str)|' + "(not all arguments converted during string formatting)" ) with pytest.raises(TypeError, match=msg): ops(pd.Series("foo", index=s.index)) From 99f1a4f73e3cef9c0b47e2ce7ed9e6af2d8001e3 Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 20:25:43 -0700 Subject: [PATCH 07/14] black pandas on setitem.py --- pandas/tests/extension/base/setitem.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/tests/extension/base/setitem.py b/pandas/tests/extension/base/setitem.py index f3560c37ab17e..46f3562cf37ee 100644 --- a/pandas/tests/extension/base/setitem.py +++ b/pandas/tests/extension/base/setitem.py @@ -289,11 +289,11 @@ def test_setitem_slice_mismatch_length_raises(self, data): msg = ( # pandas.core.arrays.period.PeriodArray # pandas.core.arrays.datetimes.DatetimeArray - "(cannot set using a slice indexer with a different length than the value)" "|" + "(cannot set using a slice indexer with a different length than the value)|" # string_arrow.ArrowStringArray - "(Length of indexer and values mismatch)" "|" + "(Length of indexer and values mismatch)|" # pandas.tests.extension.decimal.array.DecimalArray - "(cannot copy sequence with size \\d to array axis with dimension \\d)" "|" + "(cannot copy sequence with size \\d to array axis with dimension \\d)|" # All the rest "(could not broadcast input array from shape \\(\\d\\) into shape \\(\\d\\))" ) @@ -310,9 +310,9 @@ def test_setitem_scalar_key_sequence_raise(self, data): # Check the comment on test_setitem_slice_mismatch_length_raises for more info. msg = ( # pandas.core.arrays.string_arrow.ArrowStringArray - "(Must pass scalars with scalar indexer)" "|" + "(Must pass scalars with scalar indexer)|" # pandas.core.arrays.datetimes.DatetimeArray - "(Could not convert object to NumPy datetime)" "|" + "(Could not convert object to NumPy datetime)|" # All the rest "(setting an array element with a sequence)" ) From 669b4273936240babe606bd9bf68504687000e71 Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 21:00:29 -0700 Subject: [PATCH 08/14] BaseComparisonOpsTests --- pandas/tests/extension/base/ops.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/extension/base/ops.py b/pandas/tests/extension/base/ops.py index c93603398977e..4259a37ab2fb2 100644 --- a/pandas/tests/extension/base/ops.py +++ b/pandas/tests/extension/base/ops.py @@ -145,7 +145,8 @@ def _compare_other(self, s, data, op_name, other): # series s = pd.Series(data) - with pytest.raises(TypeError): + msg = "not supported between instances of '[\\w.]+' and '[\\w.]+'" + with pytest.raises(TypeError, match=msg): op(s, other) def test_compare_scalar(self, data, all_compare_operators): From ded71026ba9966cdce25e6b182bbc70e1e33bf4a Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 21:35:04 -0700 Subject: [PATCH 09/14] extension/base/ops.py --- pandas/tests/extension/base/ops.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/pandas/tests/extension/base/ops.py b/pandas/tests/extension/base/ops.py index 4259a37ab2fb2..6a1ed1924d850 100644 --- a/pandas/tests/extension/base/ops.py +++ b/pandas/tests/extension/base/ops.py @@ -30,7 +30,16 @@ def _check_op(self, s, op, other, op_name, exc=NotImplementedError): expected = s.combine(other, op) self.assert_series_equal(result, expected) else: - with pytest.raises(exc): + msg = ( + "(unsupported operand type\\(s\\) for)|" + "(cannot perform [\\w_]+ with this index type: [\\w_]+)|" + "(Object with dtype category cannot perform the numpy op [\\w_]+)|" + "(cannot add [\\w_]+ and [\\w_]+)|" + "(can't multiply sequence by non-int of type '[\\w_]+')|" + '(can only concatenate str \\(not "[\\w_]+"\\) to str)|' + "(Object with dtype category cannot perform the numpy op [\\w_]+)" + ) + with pytest.raises(exc, match=msg): op(s, other) def _check_divmod_op(self, s, op, other, exc=Exception): @@ -44,7 +53,12 @@ def _check_divmod_op(self, s, op, other, exc=Exception): self.assert_series_equal(result_div, expected_div) self.assert_series_equal(result_mod, expected_mod) else: - with pytest.raises(exc): + msg = ( + "('tuple' object has no attribute 'dtype')|" + "(cannot perform __r?divmod__ with this index type)|" + "(unsupported operand type\\(s\\) for divmod\\(\\))" + ) + with pytest.raises(exc, match=msg): divmod(s, other) @@ -111,7 +125,8 @@ def test_add_series_with_extension_array(self, data): def test_error(self, data, all_arithmetic_operators): # invalid ops op_name = all_arithmetic_operators - with pytest.raises(AttributeError): + msg = "'\\w+' object has no attribute '[\\w_]+'" + with pytest.raises(AttributeError, match=msg): getattr(data, op_name) @pytest.mark.parametrize("box", [pd.Series, pd.DataFrame]) From 798753cba1368f77df956855e82f5bf75b534882 Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 21:46:55 -0700 Subject: [PATCH 10/14] Break too long lines --- pandas/tests/arrays/boolean/test_arithmetic.py | 3 ++- pandas/tests/extension/base/setitem.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index 3dbc3f6a7dd8d..2bb2a02df9a7c 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -46,7 +46,8 @@ def test_add_mul(left_array, right_array, opname, exp): def test_sub(left_array, right_array): - msg = "the `-` operator, is not supported, use the bitwise_xor, the `\\^` operator, or the logical_xor" + msg = "the `-` operator, is not supported, use the bitwise_xor, " \ + "the `\\^` operator, or the logical_xor" with pytest.raises(TypeError, match=msg): # numpy points to ^ operator or logical_xor function instead left_array - right_array diff --git a/pandas/tests/extension/base/setitem.py b/pandas/tests/extension/base/setitem.py index 46f3562cf37ee..266a145cc572b 100644 --- a/pandas/tests/extension/base/setitem.py +++ b/pandas/tests/extension/base/setitem.py @@ -282,8 +282,9 @@ def test_setitem_loc_iloc_slice(self, data): self.assert_equal(result, expected) def test_setitem_slice_mismatch_length_raises(self, data): - # This class is a test mixin class, based on which test class it's mixed with the expected error messages can - # vary. This regular expression catches all the variants of those messages. It's formatted as a big OR + # This class is a test mixin class, based on which test class it's mixed + # with the expected error messages can vary. This regular expression + # catches all the variants of those messages. It's formatted as a big OR # statement: /m1|m2|m3|m4/ msg = ( @@ -295,7 +296,8 @@ def test_setitem_slice_mismatch_length_raises(self, data): # pandas.tests.extension.decimal.array.DecimalArray "(cannot copy sequence with size \\d to array axis with dimension \\d)|" # All the rest - "(could not broadcast input array from shape \\(\\d\\) into shape \\(\\d\\))" + "(could not broadcast input array from " + "shape \\(\\d\\) into shape \\(\\d\\))" ) arr = data[:5] with pytest.raises(ValueError, match=msg): From dde76de715000c20610e4c4b461e03724eacf522 Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 21:52:23 -0700 Subject: [PATCH 11/14] The numpy error was an external one --- pandas/tests/arrays/boolean/test_arithmetic.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index 2bb2a02df9a7c..560d63026b98e 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -46,9 +46,7 @@ def test_add_mul(left_array, right_array, opname, exp): def test_sub(left_array, right_array): - msg = "the `-` operator, is not supported, use the bitwise_xor, " \ - "the `\\^` operator, or the logical_xor" - with pytest.raises(TypeError, match=msg): + with tm.external_error_raised(TypeError): # numpy points to ^ operator or logical_xor function instead left_array - right_array From ddb14ee743aff6bdc261995aef5a13144fc0113e Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 23:03:40 -0700 Subject: [PATCH 12/14] Update RegExs to match more tests --- pandas/tests/arrays/boolean/test_arithmetic.py | 5 ++++- pandas/tests/extension/base/setitem.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index 560d63026b98e..36474f786ad00 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -101,7 +101,10 @@ def test_error_invalid_values(data, all_arithmetic_operators): with pytest.raises(TypeError, match=msg): ops("foo") - msg = "unsupported operand type\\(s\\) for" + msg = ( + "(unsupported operand type\\(s\\) for)|" + "(Concatenation operation is not implemented for NumPy arrays)" + ) with pytest.raises(TypeError, match=msg): ops(pd.Timestamp("20180101")) diff --git a/pandas/tests/extension/base/setitem.py b/pandas/tests/extension/base/setitem.py index 266a145cc572b..7e470692f9d71 100644 --- a/pandas/tests/extension/base/setitem.py +++ b/pandas/tests/extension/base/setitem.py @@ -297,7 +297,7 @@ def test_setitem_slice_mismatch_length_raises(self, data): "(cannot copy sequence with size \\d to array axis with dimension \\d)|" # All the rest "(could not broadcast input array from " - "shape \\(\\d\\) into shape \\(\\d\\))" + "shape \\(\\d,?\\) into shape \\(\\d,?\\))" ) arr = data[:5] with pytest.raises(ValueError, match=msg): From e2ec45555a9922d06caa5836eb02f878bf83eff9 Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Fri, 18 Dec 2020 23:51:49 -0700 Subject: [PATCH 13/14] Added new error messages --- pandas/tests/extension/base/ops.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/extension/base/ops.py b/pandas/tests/extension/base/ops.py index 6a1ed1924d850..94ea30b5c7d07 100644 --- a/pandas/tests/extension/base/ops.py +++ b/pandas/tests/extension/base/ops.py @@ -37,7 +37,8 @@ def _check_op(self, s, op, other, op_name, exc=NotImplementedError): "(cannot add [\\w_]+ and [\\w_]+)|" "(can't multiply sequence by non-int of type '[\\w_]+')|" '(can only concatenate str \\(not "[\\w_]+"\\) to str)|' - "(Object with dtype category cannot perform the numpy op [\\w_]+)" + "(Object with dtype category cannot perform the numpy op [\\w_]+)|" + "(Concatenation operation is not implemented for NumPy arrays)" ) with pytest.raises(exc, match=msg): op(s, other) From 50b05ef6016671b5c13ae76385c150dbc5b9aba5 Mon Sep 17 00:00:00 2001 From: Mohammad Jafar Mashhadi Date: Sat, 19 Dec 2020 09:22:34 -0700 Subject: [PATCH 14/14] Removed redundant parenthesis in regexps --- .../tests/arrays/boolean/test_arithmetic.py | 18 ++++++------- pandas/tests/extension/base/ops.py | 26 +++++++++---------- pandas/tests/extension/base/setitem.py | 16 ++++++------ 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/pandas/tests/arrays/boolean/test_arithmetic.py b/pandas/tests/arrays/boolean/test_arithmetic.py index 36474f786ad00..72b378f75c936 100644 --- a/pandas/tests/arrays/boolean/test_arithmetic.py +++ b/pandas/tests/arrays/boolean/test_arithmetic.py @@ -93,17 +93,17 @@ def test_error_invalid_values(data, all_arithmetic_operators): # invalid scalars msg = ( - "(ufunc '\\w+' did not contain a loop with signature matching types)|" - "(ufunc '\\w+' not supported for the input types, and the inputs could " - "not be safely coerced to any supported types)|" - "(\\w+ cannot perform the operation \\w+)" + "ufunc '\\w+' did not contain a loop with signature matching types|" + "ufunc '\\w+' not supported for the input types, and the inputs could " + "not be safely coerced to any supported types|" + "\\w+ cannot perform the operation \\w+" ) with pytest.raises(TypeError, match=msg): ops("foo") msg = ( - "(unsupported operand type\\(s\\) for)|" - "(Concatenation operation is not implemented for NumPy arrays)" + "unsupported operand type\\(s\\) for|" + "Concatenation operation is not implemented for NumPy arrays" ) with pytest.raises(TypeError, match=msg): ops(pd.Timestamp("20180101")) @@ -112,9 +112,9 @@ def test_error_invalid_values(data, all_arithmetic_operators): if op not in ("__mul__", "__rmul__"): # TODO(extension) numpy's mul with object array sees booleans as numbers msg = ( - "(unsupported operand type\\(s\\) for)|" - '(can only concatenate str \\(not "bool"\\) to str)|' - "(not all arguments converted during string formatting)" + "unsupported operand type\\(s\\) for|" + 'can only concatenate str \\(not "bool"\\) to str|' + "not all arguments converted during string formatting" ) with pytest.raises(TypeError, match=msg): ops(pd.Series("foo", index=s.index)) diff --git a/pandas/tests/extension/base/ops.py b/pandas/tests/extension/base/ops.py index 94ea30b5c7d07..6e65418bde58d 100644 --- a/pandas/tests/extension/base/ops.py +++ b/pandas/tests/extension/base/ops.py @@ -31,14 +31,14 @@ def _check_op(self, s, op, other, op_name, exc=NotImplementedError): self.assert_series_equal(result, expected) else: msg = ( - "(unsupported operand type\\(s\\) for)|" - "(cannot perform [\\w_]+ with this index type: [\\w_]+)|" - "(Object with dtype category cannot perform the numpy op [\\w_]+)|" - "(cannot add [\\w_]+ and [\\w_]+)|" - "(can't multiply sequence by non-int of type '[\\w_]+')|" - '(can only concatenate str \\(not "[\\w_]+"\\) to str)|' - "(Object with dtype category cannot perform the numpy op [\\w_]+)|" - "(Concatenation operation is not implemented for NumPy arrays)" + "unsupported operand type\\(s\\) for|" + "cannot perform [\\w_]+ with this index type: [\\w_]+|" + "Object with dtype category cannot perform the numpy op [\\w_]+|" + "cannot add [\\w_]+ and [\\w_]+|" + "can't multiply sequence by non-int of type '[\\w_]+'|" + 'can only concatenate str \\(not "[\\w_]+"\\) to str|' + "Object with dtype category cannot perform the numpy op [\\w_]+|" + "Concatenation operation is not implemented for NumPy arrays" ) with pytest.raises(exc, match=msg): op(s, other) @@ -55,9 +55,9 @@ def _check_divmod_op(self, s, op, other, exc=Exception): self.assert_series_equal(result_mod, expected_mod) else: msg = ( - "('tuple' object has no attribute 'dtype')|" - "(cannot perform __r?divmod__ with this index type)|" - "(unsupported operand type\\(s\\) for divmod\\(\\))" + "'tuple' object has no attribute 'dtype'|" + "cannot perform __r?divmod__ with this index type|" + "unsupported operand type\\(s\\) for divmod\\(\\)" ) with pytest.raises(exc, match=msg): divmod(s, other) @@ -126,7 +126,7 @@ def test_add_series_with_extension_array(self, data): def test_error(self, data, all_arithmetic_operators): # invalid ops op_name = all_arithmetic_operators - msg = "'\\w+' object has no attribute '[\\w_]+'" + msg = "'[\\w_]+' object has no attribute '[\\w_]+'" with pytest.raises(AttributeError, match=msg): getattr(data, op_name) @@ -161,7 +161,7 @@ def _compare_other(self, s, data, op_name, other): # series s = pd.Series(data) - msg = "not supported between instances of '[\\w.]+' and '[\\w.]+'" + msg = "not supported between instances of '[\\w._]+' and '[\\w._]+'" with pytest.raises(TypeError, match=msg): op(s, other) diff --git a/pandas/tests/extension/base/setitem.py b/pandas/tests/extension/base/setitem.py index 7e470692f9d71..e77d2b2633e88 100644 --- a/pandas/tests/extension/base/setitem.py +++ b/pandas/tests/extension/base/setitem.py @@ -290,14 +290,14 @@ def test_setitem_slice_mismatch_length_raises(self, data): msg = ( # pandas.core.arrays.period.PeriodArray # pandas.core.arrays.datetimes.DatetimeArray - "(cannot set using a slice indexer with a different length than the value)|" + "cannot set using a slice indexer with a different length than the value|" # string_arrow.ArrowStringArray - "(Length of indexer and values mismatch)|" + "Length of indexer and values mismatch|" # pandas.tests.extension.decimal.array.DecimalArray - "(cannot copy sequence with size \\d to array axis with dimension \\d)|" + "cannot copy sequence with size \\d to array axis with dimension \\d|" # All the rest - "(could not broadcast input array from " - "shape \\(\\d,?\\) into shape \\(\\d,?\\))" + "could not broadcast input array from " + "shape \\(\\d,?\\) into shape \\(\\d,?\\)" ) arr = data[:5] with pytest.raises(ValueError, match=msg): @@ -312,11 +312,11 @@ def test_setitem_scalar_key_sequence_raise(self, data): # Check the comment on test_setitem_slice_mismatch_length_raises for more info. msg = ( # pandas.core.arrays.string_arrow.ArrowStringArray - "(Must pass scalars with scalar indexer)|" + "Must pass scalars with scalar indexer|" # pandas.core.arrays.datetimes.DatetimeArray - "(Could not convert object to NumPy datetime)|" + "Could not convert object to NumPy datetime|" # All the rest - "(setting an array element with a sequence)" + "setting an array element with a sequence" ) arr = data[:5].copy() with pytest.raises(ValueError, match=msg):