@@ -49,7 +49,8 @@ def test_apply(self, float_frame):
4949
5050 # invalid axis
5151 df = DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]], index = ["a" , "a" , "c" ])
52- with pytest .raises (ValueError ):
52+ msg = "No axis named 2 for object type DataFrame"
53+ with pytest .raises (ValueError , match = msg ):
5354 df .apply (lambda x : x , 2 )
5455
5556 # GH 9573
@@ -221,18 +222,20 @@ def test_apply_broadcast_error(self, int_frame_const_col):
221222 df = int_frame_const_col
222223
223224 # > 1 ndim
224- with pytest .raises (ValueError ):
225+ msg = "too many dims to broadcast"
226+ with pytest .raises (ValueError , match = msg ):
225227 df .apply (
226228 lambda x : np .array ([1 , 2 ]).reshape (- 1 , 2 ),
227229 axis = 1 ,
228230 result_type = "broadcast" ,
229231 )
230232
231233 # cannot broadcast
232- with pytest .raises (ValueError ):
234+ msg = "cannot broadcast result"
235+ with pytest .raises (ValueError , match = msg ):
233236 df .apply (lambda x : [1 , 2 ], axis = 1 , result_type = "broadcast" )
234237
235- with pytest .raises (ValueError ):
238+ with pytest .raises (ValueError , match = msg ):
236239 df .apply (lambda x : Series ([1 , 2 ]), axis = 1 , result_type = "broadcast" )
237240
238241 def test_apply_raw (self , float_frame , mixed_type_frame ):
@@ -950,7 +953,11 @@ def test_result_type_error(self, result_type, int_frame_const_col):
950953 # allowed result_type
951954 df = int_frame_const_col
952955
953- with pytest .raises (ValueError ):
956+ msg = (
957+ "invalid value for result_type, must be one of "
958+ "{None, 'reduce', 'broadcast', 'expand'}"
959+ )
960+ with pytest .raises (ValueError , match = msg ):
954961 df .apply (lambda x : [1 , 2 , 3 ], axis = 1 , result_type = result_type )
955962
956963 @pytest .mark .parametrize (
@@ -1046,14 +1053,16 @@ def test_agg_transform(self, axis, float_frame):
10461053
10471054 def test_transform_and_agg_err (self , axis , float_frame ):
10481055 # cannot both transform and agg
1049- with pytest .raises (ValueError ):
1056+ msg = "transforms cannot produce aggregated results"
1057+ with pytest .raises (ValueError , match = msg ):
10501058 float_frame .transform (["max" , "min" ], axis = axis )
10511059
1052- with pytest .raises (ValueError ):
1060+ msg = "cannot combine transform and aggregation operations"
1061+ with pytest .raises (ValueError , match = msg ):
10531062 with np .errstate (all = "ignore" ):
10541063 float_frame .agg (["max" , "sqrt" ], axis = axis )
10551064
1056- with pytest .raises (ValueError ):
1065+ with pytest .raises (ValueError , match = msg ):
10571066 with np .errstate (all = "ignore" ):
10581067 float_frame .transform (["max" , "sqrt" ], axis = axis )
10591068
@@ -1387,7 +1396,8 @@ def test_agg_cython_table_transform(self, df, func, expected, axis):
13871396 )
13881397 def test_agg_cython_table_raises (self , df , func , expected , axis ):
13891398 # GH 21224
1390- with pytest .raises (expected ):
1399+ msg = "can't multiply sequence by non-int of type 'str'"
1400+ with pytest .raises (expected , match = msg ):
13911401 df .agg (func , axis = axis )
13921402
13931403 @pytest .mark .parametrize ("num_cols" , [2 , 3 , 5 ])
0 commit comments