@@ -97,8 +97,10 @@ def test_argsort_stable(self):
97
97
check_dtype = False )
98
98
tm .assert_series_equal (qindexer , Series (qexpected ),
99
99
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 )
102
104
103
105
def test_cumsum (self , datetime_series ):
104
106
self ._check_accum_op ('cumsum' , datetime_series )
@@ -476,8 +478,13 @@ def test_dot(self):
476
478
assert_almost_equal (a .dot (b ['1' ]), expected ['1' ])
477
479
assert_almost_equal (a .dot (b2 ['1' ]), expected ['1' ])
478
480
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 )
481
488
482
489
@pytest .mark .skipif (not PY35 ,
483
490
reason = 'matmul supported for Python>=3.5' )
@@ -541,8 +548,13 @@ def test_matmul(self):
541
548
index = ['1' , '2' , '3' ])
542
549
assert_series_equal (result , expected )
543
550
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 )
546
558
547
559
def test_clip (self , datetime_series ):
548
560
val = datetime_series .median ()
@@ -697,11 +709,13 @@ def test_isin(self):
697
709
def test_isin_with_string_scalar (self ):
698
710
# GH4763
699
711
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 ):
701
715
s .isin ('a' )
702
716
703
- with pytest . raises ( TypeError ):
704
- s = Series ([ 'aaa' , 'b' , 'c' ])
717
+ s = Series ([ 'aaa' , 'b' , 'c' ])
718
+ with pytest . raises ( TypeError , match = msg ):
705
719
s .isin ('aaa' )
706
720
707
721
def test_isin_with_i8 (self ):
@@ -771,18 +785,21 @@ def test_ptp(self):
771
785
with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
772
786
tm .assert_series_equal (s .ptp (level = 0 , skipna = False ), expected )
773
787
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 ):
775
790
with tm .assert_produces_warning (FutureWarning ,
776
791
check_stacklevel = False ):
777
792
s .ptp (axis = 1 )
778
793
779
794
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 ):
781
797
with tm .assert_produces_warning (FutureWarning ,
782
798
check_stacklevel = False ):
783
799
s .ptp ()
784
800
785
- with pytest .raises (NotImplementedError ):
801
+ msg = r"Series\.ptp does not implement numeric_only\."
802
+ with pytest .raises (NotImplementedError , match = msg ):
786
803
with tm .assert_produces_warning (FutureWarning ,
787
804
check_stacklevel = False ):
788
805
s .ptp (numeric_only = True )
@@ -1103,29 +1120,38 @@ def test_validate_any_all_out_keepdims_raises(self, kwargs, func):
1103
1120
param = list (kwargs )[0 ]
1104
1121
name = func .__name__
1105
1122
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 )
1107
1126
with pytest .raises (ValueError , match = msg ):
1108
1127
func (s , ** kwargs )
1109
1128
1110
1129
@td .skip_if_np_lt_115
1111
1130
def test_validate_sum_initial (self ):
1112
1131
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 ):
1114
1136
np .sum (s , initial = 10 )
1115
1137
1116
1138
def test_validate_median_initial (self ):
1117
1139
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 ):
1120
1144
# It seems like np.median doesn't dispatch, so we use the
1121
1145
# method instead of the ufunc.
1122
1146
s .median (overwrite_input = True )
1123
1147
1124
1148
@td .skip_if_np_lt_115
1125
1149
def test_validate_stat_keepdims (self ):
1126
1150
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 ):
1129
1155
np .sum (s , keepdims = True )
1130
1156
1131
1157
0 commit comments