@@ -1966,13 +1966,9 @@ def test_n(self, df_strings, method, n, order):
1966
1966
1967
1967
# Only expect error when 'b' is first in order, as 'a' and 'c' are
1968
1968
# unique
1969
- error_msg = (
1970
- "'b' has dtype: object, cannot use method 'nsmallest' "
1971
- "with this dtype"
1972
- )
1973
- with pytest .raises (TypeError ) as exc_info :
1969
+ error_msg = "Cannot use method '%s' with dtype object" % method
1970
+ with tm .assertRaisesRegexp (TypeError , error_msg ):
1974
1971
getattr (df , method )(n , order )
1975
- assert exc_info .value , error_msg
1976
1972
else :
1977
1973
ascending = method == 'nsmallest'
1978
1974
result = getattr (df , method )(n , order )
@@ -1986,12 +1982,11 @@ def test_n(self, df_strings, method, n, order):
1986
1982
))
1987
1983
def test_n_error (self , df_main_dtypes , method , columns ):
1988
1984
df = df_main_dtypes
1989
- with pytest .raises (TypeError ) as exc_info :
1985
+ msg = "Cannot use method '%s' with dtype %s" % (
1986
+ method , df [columns [1 ]].dtype
1987
+ )
1988
+ with tm .assertRaisesRegexp (TypeError , msg ):
1990
1989
getattr (df , method )(2 , columns )
1991
- msg = "Cannot use method '%s' with dtype %s" % (
1992
- method , df [columns [1 ]].dtype
1993
- )
1994
- assert exc_info .value , msg
1995
1990
1996
1991
def test_n_all_dtypes (self , df_main_dtypes ):
1997
1992
df = df_main_dtypes
0 commit comments