@@ -1984,16 +1984,15 @@ def test_n_error(self, df_strings):
1984
1984
'timedelta' ])
1985
1985
columns_with_errors = {'category_string' , 'string' }
1986
1986
columns_without_errors = list (set (df ) - columns_with_errors )
1987
- for column in columns_with_errors :
1988
- dtype = df [column ].dtype
1989
- for columns in (column , ['group' , column ]):
1990
- msg_template = "Cannot use method '%s' with dtype %s"
1987
+ methods = 'nsmallest' , 'nlargest'
1988
+ for col in columns_with_errors :
1989
+ for method , cols in product (methods , (col , ['group' , col ])):
1991
1990
with pytest .raises (TypeError ) as exc_info :
1992
- df . nsmallest (2 , columns )
1993
- assert exc_info . value , msg_template % ( 'nsmallest' , dtype )
1994
- with pytest . raises ( TypeError ) as exc_info :
1995
- df . nlargest ( 2 , columns )
1996
- assert exc_info .value , msg_template % ( 'nlargest' , dtype )
1991
+ getattr ( df , method ) (2 , cols )
1992
+ msg = "Cannot use method '%s' with dtype %s" % (
1993
+ method , df [ col ]. dtype
1994
+ )
1995
+ assert exc_info .value , msg
1997
1996
df .nsmallest (2 , columns_without_errors )
1998
1997
df .nsmallest (2 , ['int' , 'string' ]) # int column is unique => OK
1999
1998
0 commit comments