@@ -97,8 +97,10 @@ def test_argsort_stable(self):
9797 check_dtype = False )
9898 tm .assert_series_equal (qindexer , Series (qexpected ),
9999 check_dtype = False )
100- pytest .raises (AssertionError , tm .assert_numpy_array_equal ,
101- qindexer , mindexer )
100+ msg = (r"ndarray Expected type <(class|type) 'numpy\.ndarray'>,"
101+ r" found <class 'pandas\.core\.series\.Series'> instead" )
102+ with pytest .raises (AssertionError , match = msg ):
103+ tm .assert_numpy_array_equal (qindexer , mindexer )
102104
103105 def test_cumsum (self , datetime_series ):
104106 self ._check_accum_op ('cumsum' , datetime_series )
@@ -476,8 +478,13 @@ def test_dot(self):
476478 assert_almost_equal (a .dot (b ['1' ]), expected ['1' ])
477479 assert_almost_equal (a .dot (b2 ['1' ]), expected ['1' ])
478480
479- pytest .raises (Exception , a .dot , a .values [:3 ])
480- pytest .raises (ValueError , a .dot , b .T )
481+ msg = r"Dot product shape mismatch, \(4L?,\) vs \(3L?,\)"
482+ # exception raised is of type Exception
483+ with pytest .raises (Exception , match = msg ):
484+ a .dot (a .values [:3 ])
485+ msg = "matrices are not aligned"
486+ with pytest .raises (ValueError , match = msg ):
487+ a .dot (b .T )
481488
482489 @pytest .mark .skipif (not PY35 ,
483490 reason = 'matmul supported for Python>=3.5' )
@@ -541,8 +548,13 @@ def test_matmul(self):
541548 index = ['1' , '2' , '3' ])
542549 assert_series_equal (result , expected )
543550
544- pytest .raises (Exception , a .dot , a .values [:3 ])
545- pytest .raises (ValueError , a .dot , b .T )
551+ msg = r"Dot product shape mismatch, \(4,\) vs \(3,\)"
552+ # exception raised is of type Exception
553+ with pytest .raises (Exception , match = msg ):
554+ a .dot (a .values [:3 ])
555+ msg = "matrices are not aligned"
556+ with pytest .raises (ValueError , match = msg ):
557+ a .dot (b .T )
546558
547559 def test_clip (self , datetime_series ):
548560 val = datetime_series .median ()
@@ -697,11 +709,13 @@ def test_isin(self):
697709 def test_isin_with_string_scalar (self ):
698710 # GH4763
699711 s = Series (['A' , 'B' , 'C' , 'a' , 'B' , 'B' , 'A' , 'C' ])
700- with pytest .raises (TypeError ):
712+ msg = (r"only list-like objects are allowed to be passed to isin\(\),"
713+ r" you passed a \[str\]" )
714+ with pytest .raises (TypeError , match = msg ):
701715 s .isin ('a' )
702716
703- with pytest . raises ( TypeError ):
704- s = Series ([ 'aaa' , 'b' , 'c' ])
717+ s = Series ([ 'aaa' , 'b' , 'c' ])
718+ with pytest . raises ( TypeError , match = msg ):
705719 s .isin ('aaa' )
706720
707721 def test_isin_with_i8 (self ):
@@ -771,18 +785,21 @@ def test_ptp(self):
771785 with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
772786 tm .assert_series_equal (s .ptp (level = 0 , skipna = False ), expected )
773787
774- with pytest .raises (ValueError ):
788+ msg = r"No axis named 1 for object type <(class|type) 'type'>"
789+ with pytest .raises (ValueError , match = msg ):
775790 with tm .assert_produces_warning (FutureWarning ,
776791 check_stacklevel = False ):
777792 s .ptp (axis = 1 )
778793
779794 s = pd .Series (['a' , 'b' , 'c' , 'd' , 'e' ])
780- with pytest .raises (TypeError ):
795+ msg = r"unsupported operand type\(s\) for -: 'str' and 'str'"
796+ with pytest .raises (TypeError , match = msg ):
781797 with tm .assert_produces_warning (FutureWarning ,
782798 check_stacklevel = False ):
783799 s .ptp ()
784800
785- with pytest .raises (NotImplementedError ):
801+ msg = r"Series\.ptp does not implement numeric_only\."
802+ with pytest .raises (NotImplementedError , match = msg ):
786803 with tm .assert_produces_warning (FutureWarning ,
787804 check_stacklevel = False ):
788805 s .ptp (numeric_only = True )
@@ -1103,29 +1120,38 @@ def test_validate_any_all_out_keepdims_raises(self, kwargs, func):
11031120 param = list (kwargs )[0 ]
11041121 name = func .__name__
11051122
1106- msg = "the '{}' parameter .* {}" .format (param , name )
1123+ msg = (r"the '{arg}' parameter is not "
1124+ r"supported in the pandas "
1125+ r"implementation of {fname}\(\)" ).format (arg = param , fname = name )
11071126 with pytest .raises (ValueError , match = msg ):
11081127 func (s , ** kwargs )
11091128
11101129 @td .skip_if_np_lt_115
11111130 def test_validate_sum_initial (self ):
11121131 s = pd .Series ([1 , 2 ])
1113- with pytest .raises (ValueError , match = "the 'initial' .* sum" ):
1132+ msg = (r"the 'initial' parameter is not "
1133+ r"supported in the pandas "
1134+ r"implementation of sum\(\)" )
1135+ with pytest .raises (ValueError , match = msg ):
11141136 np .sum (s , initial = 10 )
11151137
11161138 def test_validate_median_initial (self ):
11171139 s = pd .Series ([1 , 2 ])
1118- with pytest .raises (ValueError ,
1119- match = "the 'overwrite_input' .* median" ):
1140+ msg = (r"the 'overwrite_input' parameter is not "
1141+ r"supported in the pandas "
1142+ r"implementation of median\(\)" )
1143+ with pytest .raises (ValueError , match = msg ):
11201144 # It seems like np.median doesn't dispatch, so we use the
11211145 # method instead of the ufunc.
11221146 s .median (overwrite_input = True )
11231147
11241148 @td .skip_if_np_lt_115
11251149 def test_validate_stat_keepdims (self ):
11261150 s = pd .Series ([1 , 2 ])
1127- with pytest .raises (ValueError ,
1128- match = "the 'keepdims'" ):
1151+ msg = (r"the 'keepdims' parameter is not "
1152+ r"supported in the pandas "
1153+ r"implementation of sum\(\)" )
1154+ with pytest .raises (ValueError , match = msg ):
11291155 np .sum (s , keepdims = True )
11301156
11311157
0 commit comments