Skip to content

Commit aa5339f

Browse files
author
Roger Thomas
committed
Refactor
1 parent ded42ea commit aa5339f

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

pandas/tests/frame/test_analytics.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -1984,16 +1984,15 @@ def test_n_error(self, df_strings):
19841984
'timedelta'])
19851985
columns_with_errors = {'category_string', 'string'}
19861986
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])):
19911990
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
19971996
df.nsmallest(2, columns_without_errors)
19981997
df.nsmallest(2, ['int', 'string']) # int column is unique => OK
19991998

0 commit comments

Comments
 (0)