@@ -527,9 +527,17 @@ def test_numpy_minmax_period(self):
527527 def test_min_max_categorical (self ):
528528
529529 ci = pd .CategoricalIndex (list ("aabbca" ), categories = list ("cab" ), ordered = False )
530- with pytest .raises (TypeError ):
530+ msg = (
531+ r"Categorical is not ordered for operation min\n"
532+ r"you can use .as_ordered\(\) to change the Categorical to an ordered one\n"
533+ )
534+ with pytest .raises (TypeError , match = msg ):
531535 ci .min ()
532- with pytest .raises (TypeError ):
536+ msg = (
537+ r"Categorical is not ordered for operation max\n"
538+ r"you can use .as_ordered\(\) to change the Categorical to an ordered one\n"
539+ )
540+ with pytest .raises (TypeError , match = msg ):
533541 ci .max ()
534542
535543 ci = pd .CategoricalIndex (list ("aabbca" ), categories = list ("cab" ), ordered = True )
@@ -881,16 +889,20 @@ def test_all_any_params(self):
881889 tm .assert_series_equal (s .all (level = 0 ), Series ([False , True , False ]))
882890 tm .assert_series_equal (s .any (level = 0 ), Series ([False , True , True ]))
883891
884- # bool_only is not implemented with level option.
885- with pytest .raises (NotImplementedError ):
892+ msg = "Option bool_only is not implemented with option level"
893+ with pytest .raises (NotImplementedError , match = msg ):
886894 s .any (bool_only = True , level = 0 )
887- with pytest .raises (NotImplementedError ):
895+ with pytest .raises (NotImplementedError , match = msg ):
888896 s .all (bool_only = True , level = 0 )
889897
890898 # bool_only is not implemented alone.
891- with pytest .raises (NotImplementedError ):
899+ # TODO GH38810 change this error message to:
900+ # "Series.any does not implement bool_only"
901+ msg = "Series.any does not implement numeric_only"
902+ with pytest .raises (NotImplementedError , match = msg ):
892903 s .any (bool_only = True )
893- with pytest .raises (NotImplementedError ):
904+ msg = "Series.all does not implement numeric_only."
905+ with pytest .raises (NotImplementedError , match = msg ):
894906 s .all (bool_only = True )
895907
896908 def test_all_any_boolean (self ):
@@ -1023,13 +1035,21 @@ def test_assert_idxminmax_raises(self, test_input, error_type):
10231035 """
10241036 Cases where ``Series.argmax`` and related should raise an exception
10251037 """
1026- with pytest .raises (error_type ):
1038+ msg = (
1039+ "reduction operation 'argmin' not allowed for this dtype|"
1040+ "attempt to get argmin of an empty sequence"
1041+ )
1042+ with pytest .raises (error_type , match = msg ):
10271043 test_input .idxmin ()
1028- with pytest .raises (error_type ):
1044+ with pytest .raises (error_type , match = msg ):
10291045 test_input .idxmin (skipna = False )
1030- with pytest .raises (error_type ):
1046+ msg = (
1047+ "reduction operation 'argmax' not allowed for this dtype|"
1048+ "attempt to get argmax of an empty sequence"
1049+ )
1050+ with pytest .raises (error_type , match = msg ):
10311051 test_input .idxmax ()
1032- with pytest .raises (error_type ):
1052+ with pytest .raises (error_type , match = msg ):
10331053 test_input .idxmax (skipna = False )
10341054
10351055 def test_idxminmax_with_inf (self ):
0 commit comments