Skip to content

Commit 75ac0b7

Browse files
author
Roger Thomas
committed
Merge branch 'add_more_error_tests' into fix_nsmallest_nlargest_with_n_identical_values
2 parents 3840771 + a5ce1b9 commit 75ac0b7

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

pandas/tests/frame/test_analytics.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -1966,13 +1966,9 @@ def test_n(self, df_strings, method, n, order):
19661966

19671967
# Only expect error when 'b' is first in order, as 'a' and 'c' are
19681968
# 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):
19741971
getattr(df, method)(n, order)
1975-
assert exc_info.value, error_msg
19761972
else:
19771973
ascending = method == 'nsmallest'
19781974
result = getattr(df, method)(n, order)
@@ -1986,12 +1982,11 @@ def test_n(self, df_strings, method, n, order):
19861982
))
19871983
def test_n_error(self, df_main_dtypes, method, columns):
19881984
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):
19901989
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
19951990

19961991
def test_n_all_dtypes(self, df_main_dtypes):
19971992
df = df_main_dtypes

0 commit comments

Comments
 (0)