Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove arguments for checking exception messages in Python #12424

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions python/cudf/cudf/testing/_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.

import itertools
import re
import warnings
from collections import abc
from contextlib import contextmanager
Expand Down Expand Up @@ -161,8 +160,6 @@ def assert_exceptions_equal(
lfunc_args_and_kwargs=None,
rfunc_args_and_kwargs=None,
check_exception_type=True,
compare_error_message=True,
expected_error_message=None,
):
"""Compares if two functions ``lfunc`` and ``rfunc`` raise
same exception or not.
Expand Down Expand Up @@ -190,14 +187,6 @@ def assert_exceptions_equal(
Whether to compare the exception types raised by ``lfunc``
with ``rfunc`` exception type or not. If False, ``rfunc``
is simply evaluated against `Exception` type.
compare_error_message : boolean, default True
Whether to compare the error messages raised
when calling both ``lfunc`` and
``rfunc`` or not.
expected_error_message : str, default None
Expected error message to be raised by calling ``rfunc``.
Note that ``lfunc`` error message will not be compared to
this value.

Returns
-------
Expand All @@ -223,15 +212,7 @@ def assert_exceptions_equal(
except KeyboardInterrupt:
raise
except Exception as e:
if not compare_error_message:
expected_error_message = None
elif expected_error_message is None:
expected_error_message = re.escape(str(e))

with pytest.raises(
type(e) if check_exception_type else Exception,
match=expected_error_message,
):
with pytest.raises(type(e) if check_exception_type else Exception):
rfunc(*rfunc_args, **rfunc_kwargs)
else:
raise AssertionError("Expected to fail with an Exception.")
Expand Down
8 changes: 1 addition & 7 deletions python/cudf/cudf/tests/test_categorical.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2022, NVIDIA CORPORATION.
# Copyright (c) 2018-2023, NVIDIA CORPORATION.

import operator
import string
Expand Down Expand Up @@ -136,7 +136,6 @@ def test_categorical_compare_unordered():
rfunc=operator.lt,
lfunc_args_and_kwargs=([pdsr, pdsr],),
rfunc_args_and_kwargs=([sr, sr],),
compare_error_message=False,
)


Expand Down Expand Up @@ -182,7 +181,6 @@ def test_categorical_binary_add():
rfunc=operator.add,
lfunc_args_and_kwargs=([pdsr, pdsr],),
rfunc_args_and_kwargs=([sr, sr],),
compare_error_message=False,
)


Expand Down Expand Up @@ -260,7 +258,6 @@ def test_cat_series_binop_error():
rfunc=operator.add,
lfunc_args_and_kwargs=([pdf["a"], pdf["b"]],),
rfunc_args_and_kwargs=([df["a"], df["b"]],),
compare_error_message=False,
)

# lhs is numerical
Expand All @@ -269,7 +266,6 @@ def test_cat_series_binop_error():
rfunc=operator.add,
lfunc_args_and_kwargs=([pdf["b"], pdf["a"]],),
rfunc_args_and_kwargs=([df["b"], df["a"]],),
compare_error_message=False,
)


Expand Down Expand Up @@ -539,7 +535,6 @@ def test_categorical_remove_categories(pd_str_cat, inplace):
rfunc=cd_sr.cat.remove_categories,
lfunc_args_and_kwargs=([["a", "d"]], {"inplace": inplace}),
rfunc_args_and_kwargs=([["a", "d"]], {"inplace": inplace}),
expected_error_message="removals must all be in old categories",
)


Expand Down Expand Up @@ -783,7 +778,6 @@ def test_add_categories_error(data, add):
gds.cat.add_categories,
([add],),
([add],),
compare_error_message=False,
)


Expand Down
3 changes: 1 addition & 2 deletions python/cudf/cudf/tests/test_column.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2022, NVIDIA CORPORATION.
# Copyright (c) 2020-2023, NVIDIA CORPORATION.

import cupy as cp
import numpy as np
Expand Down Expand Up @@ -308,7 +308,6 @@ def test_column_view_invalid_numeric_to_numeric(data, from_dtype, to_dtype):
rfunc=gpu_data.view,
lfunc_args_and_kwargs=([to_dtype],),
rfunc_args_and_kwargs=([to_dtype],),
expected_error_message="Can not divide",
)


Expand Down
13 changes: 1 addition & 12 deletions python/cudf/cudf/tests/test_concat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright (c) 2018-2022, NVIDIA CORPORATION.
# Copyright (c) 2018-2023, NVIDIA CORPORATION.

import re
from decimal import Decimal

import numpy as np
Expand Down Expand Up @@ -138,10 +137,6 @@ def test_concat_errors():
rfunc=gd.concat,
lfunc_args_and_kwargs=([], {"objs": [df, df.index, df.x]}),
rfunc_args_and_kwargs=([], {"objs": [gdf, gdf.index, gdf.x]}),
expected_error_message=re.escape(
"`concat` cannot concatenate objects of "
"types: ['DataFrame', 'RangeIndex', 'Series']."
),
)

# Unknown type
Expand All @@ -150,9 +145,6 @@ def test_concat_errors():
rfunc=gd.concat,
lfunc_args_and_kwargs=([], {"objs": ["bar", "foo"]}),
rfunc_args_and_kwargs=([], {"objs": ["bar", "foo"]}),
expected_error_message=re.escape(
"cannot concatenate object of type <class 'str'>"
),
)

# Mismatched index dtypes
Expand All @@ -172,9 +164,6 @@ def test_concat_errors():
{"objs": [gdf.to_pandas(), gdf2.to_pandas()], "axis": "bad_value"},
),
rfunc_args_and_kwargs=([], {"objs": [gdf, gdf2], "axis": "bad_value"}),
expected_error_message=re.escape(
'`axis` must be 0 / "index"' ' or 1 / "columns", got: None'
),
)


Expand Down
4 changes: 1 addition & 3 deletions python/cudf/cudf/tests/test_csv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2022, NVIDIA CORPORATION.
# Copyright (c) 2018-2023, NVIDIA CORPORATION.

import gzip
import os
Expand Down Expand Up @@ -2101,15 +2101,13 @@ def test_csv_sep_error():
rfunc=gdf.to_csv,
lfunc_args_and_kwargs=([], {"sep": "abc"}),
rfunc_args_and_kwargs=([], {"sep": "abc"}),
expected_error_message='"sep" must be a 1-character string',
)

assert_exceptions_equal(
lfunc=pdf.to_csv,
rfunc=gdf.to_csv,
lfunc_args_and_kwargs=([], {"sep": 1}),
rfunc_args_and_kwargs=([], {"sep": 1}),
expected_error_message='"sep" must be string, not int',
)


Expand Down
19 changes: 1 addition & 18 deletions python/cudf/cudf/tests/test_dataframe.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2022, NVIDIA CORPORATION.
# Copyright (c) 2018-2023, NVIDIA CORPORATION.

import array as arr
import datetime
Expand Down Expand Up @@ -617,39 +617,34 @@ def test_dataframe_drop_error():
rfunc=df.drop,
lfunc_args_and_kwargs=([], {"columns": "d"}),
rfunc_args_and_kwargs=([], {"columns": "d"}),
expected_error_message="column 'd' does not exist",
)

assert_exceptions_equal(
lfunc=pdf.drop,
rfunc=df.drop,
lfunc_args_and_kwargs=([], {"columns": ["a", "d", "b"]}),
rfunc_args_and_kwargs=([], {"columns": ["a", "d", "b"]}),
expected_error_message="column 'd' does not exist",
)

assert_exceptions_equal(
lfunc=pdf.drop,
rfunc=df.drop,
lfunc_args_and_kwargs=(["a"], {"columns": "a", "axis": 1}),
rfunc_args_and_kwargs=(["a"], {"columns": "a", "axis": 1}),
expected_error_message="Cannot specify both",
)

assert_exceptions_equal(
lfunc=pdf.drop,
rfunc=df.drop,
lfunc_args_and_kwargs=([], {"axis": 1}),
rfunc_args_and_kwargs=([], {"axis": 1}),
expected_error_message="Need to specify at least",
)

assert_exceptions_equal(
lfunc=pdf.drop,
rfunc=df.drop,
lfunc_args_and_kwargs=([[2, 0]],),
rfunc_args_and_kwargs=([[2, 0]],),
expected_error_message="One or more values not found in axis",
)


Expand Down Expand Up @@ -725,7 +720,6 @@ def test_dataframe_drop_raises():
rfunc=df.drop,
lfunc_args_and_kwargs=(["p"],),
rfunc_args_and_kwargs=(["p"],),
expected_error_message="One or more values not found in axis",
)

# label dtype mismatch
Expand All @@ -734,7 +728,6 @@ def test_dataframe_drop_raises():
rfunc=df.drop,
lfunc_args_and_kwargs=([3],),
rfunc_args_and_kwargs=([3],),
expected_error_message="One or more values not found in axis",
)

expect = pdf.drop("p", errors="ignore")
Expand All @@ -747,7 +740,6 @@ def test_dataframe_drop_raises():
rfunc=df.drop,
lfunc_args_and_kwargs=([], {"columns": "p"}),
rfunc_args_and_kwargs=([], {"columns": "p"}),
expected_error_message="column 'p' does not exist",
)

expect = pdf.drop(columns="p", errors="ignore")
Expand All @@ -760,7 +752,6 @@ def test_dataframe_drop_raises():
rfunc=df.drop,
lfunc_args_and_kwargs=([], {"labels": "p", "axis": 1}),
rfunc_args_and_kwargs=([], {"labels": "p", "axis": 1}),
expected_error_message="column 'p' does not exist",
)

expect = pdf.drop(labels="p", axis=1, errors="ignore")
Expand Down Expand Up @@ -2292,7 +2283,6 @@ def test_arithmetic_binops_df(pdf, gdf, binop, other):
rfunc=binop,
lfunc_args_and_kwargs=([pdf, other], {}),
rfunc_args_and_kwargs=([gdf, cudf_other], {}),
compare_error_message=False,
)
else:
if isinstance(other, (pd.Series, pd.DataFrame)):
Expand Down Expand Up @@ -2339,7 +2329,6 @@ def test_comparison_binops_df(pdf, gdf, binop, other):
rfunc=binop,
lfunc_args_and_kwargs=([pdf, other], {}),
rfunc_args_and_kwargs=([gdf, cudf_other], {}),
compare_error_message=False,
)
else:
if isinstance(other, (pd.Series, pd.DataFrame)):
Expand Down Expand Up @@ -2387,7 +2376,6 @@ def test_comparison_binops_df_reindexing(request, pdf, gdf, binop, other):
rfunc=binop,
lfunc_args_and_kwargs=([pdf, other], {}),
rfunc_args_and_kwargs=([gdf, cudf_other], {}),
compare_error_message=False,
)
else:
request.applymarker(
Expand Down Expand Up @@ -2945,7 +2933,6 @@ def test_reset_index_dup_level_name(level, drop, inplace, col_level, col_fill):
[],
{"level": level, "drop": drop, "inplace": inplace},
),
expected_error_message="occurs multiple times, use a level number",
)
return

Expand Down Expand Up @@ -5965,9 +5952,6 @@ def test_df_sr_mask_where(data, condition, other, error, inplace):
[gs_condition],
{"other": gs_other, "inplace": inplace},
),
compare_error_message=False
if error is NotImplementedError
else True,
)

assert_exceptions_equal(
Expand All @@ -5981,7 +5965,6 @@ def test_df_sr_mask_where(data, condition, other, error, inplace):
[gs_condition],
{"other": gs_other, "inplace": inplace},
),
compare_error_message=False,
)


Expand Down
Loading