From cf26425c396ca04c51e4ccffee6b15975e1d4780 Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 4 Jan 2023 16:52:03 -0800 Subject: [PATCH] Remove arguments for checking exception messages in Python (#12424) This PR removes support for checking exception messages from `assert_exceptions_equal`. See #12076 for the same change made in C++, #10200 for more context, and #7917 for the change in cudf Python's developer documentation where we officially changed our policy to not consider exception payloads part of the stable API. Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Ashwin Srinath (https://github.com/shwina) URL: https://github.com/rapidsai/cudf/pull/12424 --- python/cudf/cudf/testing/_utils.py | 23 ++------------------- python/cudf/cudf/tests/test_categorical.py | 8 +------- python/cudf/cudf/tests/test_column.py | 3 +-- python/cudf/cudf/tests/test_concat.py | 13 +----------- python/cudf/cudf/tests/test_csv.py | 4 +--- python/cudf/cudf/tests/test_dataframe.py | 19 +---------------- python/cudf/cudf/tests/test_datetime.py | 21 +------------------ python/cudf/cudf/tests/test_duplicates.py | 5 +---- python/cudf/cudf/tests/test_groupby.py | 5 +---- python/cudf/cudf/tests/test_index.py | 16 +-------------- python/cudf/cudf/tests/test_indexing.py | 12 +---------- python/cudf/cudf/tests/test_multiindex.py | 10 ++------- python/cudf/cudf/tests/test_quantiles.py | 5 +---- python/cudf/cudf/tests/test_reductions.py | 17 ++------------- python/cudf/cudf/tests/test_replace.py | 6 +----- python/cudf/cudf/tests/test_series.py | 8 +------- python/cudf/cudf/tests/test_seriesmap.py | 4 +--- python/cudf/cudf/tests/test_setitem.py | 7 +------ python/cudf/cudf/tests/test_sorting.py | 4 +--- python/cudf/cudf/tests/test_stats.py | 4 +--- python/cudf/cudf/tests/test_string.py | 20 +++--------------- python/cudf/cudf/tests/test_timedelta.py | 24 +--------------------- 22 files changed, 27 insertions(+), 211 deletions(-) diff --git a/python/cudf/cudf/testing/_utils.py b/python/cudf/cudf/testing/_utils.py index a6f55df4bcf..ee3dbd85131 100644 --- a/python/cudf/cudf/testing/_utils.py +++ b/python/cudf/cudf/testing/_utils.py @@ -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 @@ -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. @@ -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 ------- @@ -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.") diff --git a/python/cudf/cudf/tests/test_categorical.py b/python/cudf/cudf/tests/test_categorical.py index 45b1891883e..fa8981cf7e3 100644 --- a/python/cudf/cudf/tests/test_categorical.py +++ b/python/cudf/cudf/tests/test_categorical.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. import operator import string @@ -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, ) @@ -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, ) @@ -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 @@ -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, ) @@ -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", ) @@ -783,7 +778,6 @@ def test_add_categories_error(data, add): gds.cat.add_categories, ([add],), ([add],), - compare_error_message=False, ) diff --git a/python/cudf/cudf/tests/test_column.py b/python/cudf/cudf/tests/test_column.py index 467c88b200f..75b82baf2e8 100644 --- a/python/cudf/cudf/tests/test_column.py +++ b/python/cudf/cudf/tests/test_column.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. import cupy as cp import numpy as np @@ -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", ) diff --git a/python/cudf/cudf/tests/test_concat.py b/python/cudf/cudf/tests/test_concat.py index 20e1c3624da..e8b863fdaea 100644 --- a/python/cudf/cudf/tests/test_concat.py +++ b/python/cudf/cudf/tests/test_concat.py @@ -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 @@ -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 @@ -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 " - ), ) # Mismatched index dtypes @@ -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' - ), ) diff --git a/python/cudf/cudf/tests/test_csv.py b/python/cudf/cudf/tests/test_csv.py index 46cf059efe9..249c4e26a86 100644 --- a/python/cudf/cudf/tests/test_csv.py +++ b/python/cudf/cudf/tests/test_csv.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. import gzip import os @@ -2101,7 +2101,6 @@ 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( @@ -2109,7 +2108,6 @@ def test_csv_sep_error(): 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', ) diff --git a/python/cudf/cudf/tests/test_dataframe.py b/python/cudf/cudf/tests/test_dataframe.py index cb9345444f9..8cb00187895 100644 --- a/python/cudf/cudf/tests/test_dataframe.py +++ b/python/cudf/cudf/tests/test_dataframe.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. import array as arr import datetime @@ -617,7 +617,6 @@ 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( @@ -625,7 +624,6 @@ def test_dataframe_drop_error(): 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( @@ -633,7 +631,6 @@ def test_dataframe_drop_error(): 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( @@ -641,7 +638,6 @@ def test_dataframe_drop_error(): 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( @@ -649,7 +645,6 @@ def test_dataframe_drop_error(): 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", ) @@ -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 @@ -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") @@ -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") @@ -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") @@ -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)): @@ -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)): @@ -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( @@ -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 @@ -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( @@ -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, ) diff --git a/python/cudf/cudf/tests/test_datetime.py b/python/cudf/cudf/tests/test_datetime.py index 109f27f4cb5..5616cea42ba 100644 --- a/python/cudf/cudf/tests/test_datetime.py +++ b/python/cudf/cudf/tests/test_datetime.py @@ -1,8 +1,7 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. import datetime import operator -import re import cupy as cp import numpy as np @@ -668,8 +667,6 @@ def test_to_datetime_errors(data): cudf.to_datetime, ([pd_data],), ([gd_data],), - compare_error_message=False, - expected_error_message="Given date string not likely a datetime.", ) @@ -867,9 +864,6 @@ def test_str_to_datetime_error(): lfunc_args_and_kwargs=(["datetime64[s]"],), rfunc_args_and_kwargs=(["datetime64[s]"],), check_exception_type=False, - expected_error_message=re.escape( - "Could not convert `None` value to datetime" - ), ) @@ -989,7 +983,6 @@ def test_datetime_series_ops_with_scalars(data, other_scalars, dtype, op): rfunc=operator.sub, lfunc_args_and_kwargs=([other_scalars, psr],), rfunc_args_and_kwargs=([other_scalars, gsr],), - compare_error_message=False, ) @@ -1047,7 +1040,6 @@ def test_datetime_invalid_ops(): rfunc=operator.add, lfunc_args_and_kwargs=([psr, pd.Timestamp(1513393355.5, unit="s")],), rfunc_args_and_kwargs=([sr, pd.Timestamp(1513393355.5, unit="s")],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1055,7 +1047,6 @@ def test_datetime_invalid_ops(): rfunc=operator.truediv, lfunc_args_and_kwargs=([psr, pd.Timestamp(1513393355.5, unit="s")],), rfunc_args_and_kwargs=([sr, pd.Timestamp(1513393355.5, unit="s")],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1063,7 +1054,6 @@ def test_datetime_invalid_ops(): rfunc=operator.add, lfunc_args_and_kwargs=([psr, psr],), rfunc_args_and_kwargs=([sr, sr],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1071,7 +1061,6 @@ def test_datetime_invalid_ops(): rfunc=operator.floordiv, lfunc_args_and_kwargs=([psr, psr],), rfunc_args_and_kwargs=([sr, sr],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1079,7 +1068,6 @@ def test_datetime_invalid_ops(): rfunc=operator.floordiv, lfunc_args_and_kwargs=([psr, pd.Timestamp(1513393355.5, unit="s")],), rfunc_args_and_kwargs=([sr, pd.Timestamp(1513393355.5, unit="s")],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1087,7 +1075,6 @@ def test_datetime_invalid_ops(): rfunc=operator.add, lfunc_args_and_kwargs=([psr, 1],), rfunc_args_and_kwargs=([sr, 1],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1095,7 +1082,6 @@ def test_datetime_invalid_ops(): rfunc=operator.truediv, lfunc_args_and_kwargs=([psr, "a"],), rfunc_args_and_kwargs=([sr, "a"],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1103,7 +1089,6 @@ def test_datetime_invalid_ops(): rfunc=operator.mul, lfunc_args_and_kwargs=([psr, 1],), rfunc_args_and_kwargs=([sr, 1],), - compare_error_message=False, ) @@ -1287,10 +1272,6 @@ def test_datetime_to_datetime_error(): lfunc_args_and_kwargs=(["02-Oct-2017 09:30", "%d-%B-%Y %H:%M"],), rfunc_args_and_kwargs=(["02-Oct-2017 09:30", "%d-%B-%Y %H:%M"],), check_exception_type=False, - expected_error_message=re.escape( - "errors parameter has to be either one of: ['ignore', 'raise', " - "'coerce', 'warn'], found: %d-%B-%Y %H:%M" - ), ) diff --git a/python/cudf/cudf/tests/test_duplicates.py b/python/cudf/cudf/tests/test_duplicates.py index cc58b7ba1f5..8a83ec150bc 100644 --- a/python/cudf/cudf/tests/test_duplicates.py +++ b/python/cudf/cudf/tests/test_duplicates.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. import itertools import random @@ -48,7 +48,6 @@ def test_duplicated_with_misspelled_column_name(subset): rfunc=gdf.drop_duplicates, lfunc_args_and_kwargs=([subset],), rfunc_args_and_kwargs=([subset],), - compare_error_message=False, ) @@ -376,7 +375,6 @@ def test_dataframe_drop_duplicates_method(): rfunc=gdf.drop_duplicates, lfunc_args_and_kwargs=(["n3"],), rfunc_args_and_kwargs=(["n3"],), - expected_error_message="columns {'n3'} do not exist", ) assert_exceptions_equal( @@ -384,7 +382,6 @@ def test_dataframe_drop_duplicates_method(): rfunc=gdf.drop_duplicates, lfunc_args_and_kwargs=([["n1", "n4", "n3"]],), rfunc_args_and_kwargs=([["n1", "n4", "n3"]],), - expected_error_message="columns {'n[34]', 'n[34]'} do not exist", ) diff --git a/python/cudf/cudf/tests/test_groupby.py b/python/cudf/cudf/tests/test_groupby.py index 78b1327e7e1..79a76f30c1e 100644 --- a/python/cudf/cudf/tests/test_groupby.py +++ b/python/cudf/cudf/tests/test_groupby.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. import datetime import itertools @@ -696,7 +696,6 @@ def test_advanced_groupby_levels(): rfunc=gdg.groupby, lfunc_args_and_kwargs=([], {"level": 2}), rfunc_args_and_kwargs=([], {"level": 2}), - expected_error_message="Invalid level number", ) @@ -1397,7 +1396,6 @@ def test_raise_data_error(): assert_exceptions_equal( pdf.groupby("a").mean, gdf.groupby("a").mean, - compare_error_message=False, ) @@ -1813,7 +1811,6 @@ def test_groupby_nonempty_no_keys(pdf): assert_exceptions_equal( lambda: pdf.groupby([]), lambda: gdf.groupby([]), - compare_error_message=False, ) diff --git a/python/cudf/cudf/tests/test_index.py b/python/cudf/cudf/tests/test_index.py index 1c1ed9bba98..5b0eca1c635 100644 --- a/python/cudf/cudf/tests/test_index.py +++ b/python/cudf/cudf/tests/test_index.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. """ Test related to Index @@ -676,7 +676,6 @@ def test_index_where(data, condition, other, error): rfunc=gs.where, lfunc_args_and_kwargs=([ps_condition], {"other": ps_other}), rfunc_args_and_kwargs=([gs_condition], {"other": gs_other}), - compare_error_message=False, ) @@ -1116,7 +1115,6 @@ def test_index_append_error(data, other): rfunc=gd_data.append, lfunc_args_and_kwargs=([[sr.to_pandas()]],), rfunc_args_and_kwargs=([[sr]],), - expected_error_message=r"all inputs must be Index", ) @@ -1993,7 +1991,6 @@ def test_get_loc_single_unique_numeric(idx, key, method): rfunc=gi.get_loc, lfunc_args_and_kwargs=([], {"key": key, "method": method}), rfunc_args_and_kwargs=([], {"key": key, "method": method}), - compare_error_message=False, ) else: with expect_warning_if(method is not None): @@ -2026,7 +2023,6 @@ def test_get_loc_rangeindex(idx, key, method): rfunc=gi.get_loc, lfunc_args_and_kwargs=([], {"key": key, "method": method}), rfunc_args_and_kwargs=([], {"key": key, "method": method}), - compare_error_message=False, ) else: with expect_warning_if(method is not None): @@ -2056,7 +2052,6 @@ def test_get_loc_single_duplicate_numeric(idx, key, method): rfunc=gi.get_loc, lfunc_args_and_kwargs=([], {"key": key, "method": method}), rfunc_args_and_kwargs=([], {"key": key, "method": method}), - compare_error_message=False, ) else: with expect_warning_if(method is not None): @@ -2090,7 +2085,6 @@ def test_get_loc_single_unique_string(idx, key, method): rfunc=gi.get_loc, lfunc_args_and_kwargs=([], {"key": key, "method": method}), rfunc_args_and_kwargs=([], {"key": key, "method": method}), - compare_error_message=False, ) else: with expect_warning_if(method is not None): @@ -2116,7 +2110,6 @@ def test_get_loc_single_duplicate_string(idx, key, method): rfunc=gi.get_loc, lfunc_args_and_kwargs=([], {"key": key, "method": method}), rfunc_args_and_kwargs=([], {"key": key, "method": method}), - compare_error_message=False, ) else: with expect_warning_if(method is not None): @@ -2153,7 +2146,6 @@ def test_get_loc_multi_numeric(idx, key, method): rfunc=gi.get_loc, lfunc_args_and_kwargs=([], {"key": key, "method": method}), rfunc_args_and_kwargs=([], {"key": key, "method": method}), - compare_error_message=False, ) else: with expect_warning_if(method is not None): @@ -2201,7 +2193,6 @@ def test_get_loc_multi_numeric_deviate(idx, key, result, method): rfunc=gi.get_loc, lfunc_args_and_kwargs=([], {"key": key, "method": method}), rfunc_args_and_kwargs=([], {"key": key, "method": method}), - compare_error_message=False, ) else: expected = result @@ -2280,7 +2271,6 @@ def test_get_loc_multi_string(idx, key, method): rfunc=gi.get_loc, lfunc_args_and_kwargs=([], {"key": key, "method": method}), rfunc_args_and_kwargs=([], {"key": key, "method": method}), - compare_error_message=False, ) else: with expect_warning_if(method is not None): @@ -2571,10 +2561,6 @@ def test_isin_multiindex(data, values, level, err): lfunc_args_and_kwargs=([values], {"level": level}), rfunc_args_and_kwargs=([values], {"level": level}), check_exception_type=False, - expected_error_message=re.escape( - "values need to be a Multi-Index or set/list-like tuple " - "squences when `level=None`." - ), ) diff --git a/python/cudf/cudf/tests/test_indexing.py b/python/cudf/cudf/tests/test_indexing.py index f7c7346c91c..634466e92a3 100644 --- a/python/cudf/cudf/tests/test_indexing.py +++ b/python/cudf/cudf/tests/test_indexing.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2022, NVIDIA CORPORATION. +# Copyright (c) 2021-2023, NVIDIA CORPORATION. from itertools import combinations @@ -1214,32 +1214,26 @@ def test_out_of_bounds_indexing(): assert_exceptions_equal( lambda: psr[[0, 1, 9]], lambda: gsr[[0, 1, 9]], - compare_error_message=False, ) assert_exceptions_equal( lambda: psr[[0, 1, -4]], lambda: gsr[[0, 1, -4]], - compare_error_message=False, ) assert_exceptions_equal( lambda: psr.__setitem__([0, 1, 9], 2), lambda: gsr.__setitem__([0, 1, 9], 2), - compare_error_message=False, ) assert_exceptions_equal( lambda: psr.__setitem__([0, 1, -4], 2), lambda: gsr.__setitem__([0, 1, -4], 2), - compare_error_message=False, ) assert_exceptions_equal( lambda: psr[4:6].iloc.__setitem__(-1, 2), lambda: gsr[4:6].iloc.__setitem__(-1, 2), - compare_error_message=False, ) assert_exceptions_equal( lambda: psr[4:6].iloc.__setitem__(1, 2), lambda: gsr[4:6].iloc.__setitem__(1, 2), - compare_error_message=False, ) @@ -1679,10 +1673,6 @@ def test_dataframe_indexing_setitem_np_cp_array(array, is_error): [(slice(None, None, None), ["a", "b"]), array], {}, ), - compare_error_message=False, - expected_error_message="shape mismatch: value array of shape " - "(10, 3) could not be broadcast to indexing " - "result of shape (10, 2)", ) diff --git a/python/cudf/cudf/tests/test_multiindex.py b/python/cudf/cudf/tests/test_multiindex.py index a073e1f55bf..d27d6732226 100644 --- a/python/cudf/cudf/tests/test_multiindex.py +++ b/python/cudf/cudf/tests/test_multiindex.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2022, NVIDIA CORPORATION. +# Copyright (c) 2019-2023, NVIDIA CORPORATION. """ Test related to MultiIndex @@ -46,7 +46,6 @@ def test_multiindex_levels_codes_validation(): rfunc=cudf.MultiIndex, lfunc_args_and_kwargs=([levels, [0, 1]],), rfunc_args_and_kwargs=([levels, [0, 1]],), - compare_error_message=False, ) # Codes don't match levels @@ -55,7 +54,6 @@ def test_multiindex_levels_codes_validation(): rfunc=cudf.MultiIndex, lfunc_args_and_kwargs=([levels, [[0], [1], [1]]],), rfunc_args_and_kwargs=([levels, [[0], [1], [1]]],), - compare_error_message=False, ) # Largest code greater than number of levels @@ -64,7 +62,6 @@ def test_multiindex_levels_codes_validation(): rfunc=cudf.MultiIndex, lfunc_args_and_kwargs=([levels, [[0, 1], [0, 2]]],), rfunc_args_and_kwargs=([levels, [[0, 1], [0, 2]]],), - compare_error_message=False, ) # Unequal code lengths @@ -73,12 +70,9 @@ def test_multiindex_levels_codes_validation(): rfunc=cudf.MultiIndex, lfunc_args_and_kwargs=([levels, [[0, 1], [0]]],), rfunc_args_and_kwargs=([levels, [[0, 1], [0]]],), - compare_error_message=False, ) # Didn't pass levels and codes - assert_exceptions_equal( - lfunc=pd.MultiIndex, rfunc=cudf.MultiIndex, compare_error_message=False - ) + assert_exceptions_equal(lfunc=pd.MultiIndex, rfunc=cudf.MultiIndex) # Didn't pass non zero levels and codes assert_exceptions_equal( diff --git a/python/cudf/cudf/tests/test_quantiles.py b/python/cudf/cudf/tests/test_quantiles.py index 72b36d8a1a6..53b06e64a91 100644 --- a/python/cudf/cudf/tests/test_quantiles.py +++ b/python/cudf/cudf/tests/test_quantiles.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. import re @@ -62,9 +62,6 @@ def test_quantile_range_error(q): rfunc=gs.quantile, lfunc_args_and_kwargs=([q],), rfunc_args_and_kwargs=([q],), - expected_error_message=re.escape( - "percentiles should all be in the interval [0, 1]" - ), ) diff --git a/python/cudf/cudf/tests/test_reductions.py b/python/cudf/cudf/tests/test_reductions.py index a24fef93f89..4b45b27968d 100644 --- a/python/cudf/cudf/tests/test_reductions.py +++ b/python/cudf/cudf/tests/test_reductions.py @@ -1,7 +1,6 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. -import re from decimal import Decimal from itertools import product @@ -287,11 +286,6 @@ def test_datetime_unsupported_reductions(op): utils.assert_exceptions_equal( lfunc=getattr(psr, op), rfunc=getattr(gsr, op), - expected_error_message=re.escape( - "cannot perform " - + ("kurtosis" if op == "kurt" else op) - + " with type datetime64[ns]" - ), ) @@ -303,11 +297,6 @@ def test_timedelta_unsupported_reductions(op): utils.assert_exceptions_equal( lfunc=getattr(psr, op), rfunc=getattr(gsr, op), - expected_error_message=re.escape( - "cannot perform " - + ("kurtosis" if op == "kurt" else op) - + " with type timedelta64[ns]" - ), ) @@ -316,6 +305,4 @@ def test_categorical_reductions(op): gsr = cudf.Series([1, 2, 3, None], dtype="category") psr = gsr.to_pandas() - utils.assert_exceptions_equal( - getattr(psr, op), getattr(gsr, op), compare_error_message=False - ) + utils.assert_exceptions_equal(getattr(psr, op), getattr(gsr, op)) diff --git a/python/cudf/cudf/tests/test_replace.py b/python/cudf/cudf/tests/test_replace.py index 1133e9fe50c..9e93dd6d227 100644 --- a/python/cudf/cudf/tests/test_replace.py +++ b/python/cudf/cudf/tests/test_replace.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. import re from decimal import Decimal @@ -1067,7 +1067,6 @@ def test_replace_df_error(): rfunc=gdf.replace, lfunc_args_and_kwargs=([], {"to_replace": -1, "value": []}), rfunc_args_and_kwargs=([], {"to_replace": -1, "value": []}), - compare_error_message=False, ) @@ -1247,9 +1246,6 @@ def test_series_replace_errors(): rfunc=gsr.replace, lfunc_args_and_kwargs=([[1, 2], [1]],), rfunc_args_and_kwargs=([[1, 2], [1]],), - expected_error_message=re.escape( - "Replacement lists must be of same length. " "Expected 2, got 1." - ), ) assert_exceptions_equal( diff --git a/python/cudf/cudf/tests/test_series.py b/python/cudf/cudf/tests/test_series.py index 0c72a0d8fee..6a1245a1582 100644 --- a/python/cudf/cudf/tests/test_series.py +++ b/python/cudf/cudf/tests/test_series.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. import hashlib import operator @@ -1163,7 +1163,6 @@ def test_series_drop_edge_inputs(): rfunc=gs.drop, lfunc_args_and_kwargs=(["a"], {"columns": "a", "axis": 1}), rfunc_args_and_kwargs=(["a"], {"columns": "a", "axis": 1}), - compare_error_message=False, ) assert_exceptions_equal( @@ -1171,7 +1170,6 @@ def test_series_drop_edge_inputs(): rfunc=gs.drop, lfunc_args_and_kwargs=([], {}), rfunc_args_and_kwargs=([], {}), - expected_error_message="Need to specify at least one", ) assert_exceptions_equal( @@ -1179,7 +1177,6 @@ def test_series_drop_edge_inputs(): rfunc=gs.drop, lfunc_args_and_kwargs=(["b"], {"axis": 1}), rfunc_args_and_kwargs=(["b"], {"axis": 1}), - expected_error_message="No axis named 1", ) @@ -1192,7 +1189,6 @@ def test_series_drop_raises(): rfunc=gs.drop, lfunc_args_and_kwargs=(["p"],), rfunc_args_and_kwargs=(["p"],), - expected_error_message="One or more values not found in axis", ) # dtype specified mismatch @@ -1201,7 +1197,6 @@ def test_series_drop_raises(): rfunc=gs.drop, lfunc_args_and_kwargs=([3],), rfunc_args_and_kwargs=([3],), - expected_error_message="One or more values not found in axis", ) expect = ps.drop("p", errors="ignore") @@ -1501,7 +1496,6 @@ def test_reset_index_dup_level_name_exceptions(): [], {"level": [None]}, ), - expected_error_message="occurs multiple times, use a level number", ) # Cannot use drop=False and inplace=True to turn a series into dataframe. diff --git a/python/cudf/cudf/tests/test_seriesmap.py b/python/cudf/cudf/tests/test_seriesmap.py index 4ed6bf7afdd..9da08e483c9 100644 --- a/python/cudf/cudf/tests/test_seriesmap.py +++ b/python/cudf/cudf/tests/test_seriesmap.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. from itertools import product from math import floor @@ -92,6 +92,4 @@ def test_series_map_non_unique_index(): check_exception_type=False, lfunc_args_and_kwargs=([pd_map_series],), rfunc_args_and_kwargs=([gd_map_series],), - expected_error_message="Reindexing only valid with uniquely" - " valued Index objects", ) diff --git a/python/cudf/cudf/tests/test_setitem.py b/python/cudf/cudf/tests/test_setitem.py index 0298a62b9d2..6b2fb90e95b 100644 --- a/python/cudf/cudf/tests/test_setitem.py +++ b/python/cudf/cudf/tests/test_setitem.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. import numpy as np import pandas as pd @@ -215,7 +215,6 @@ def test_column_set_unequal_length_object_by_mask(): gsr.__setitem__, ([mask, replace_data_1], {}), ([mask, replace_data_1], {}), - compare_error_message=False, ) psr = pd.Series(data) @@ -225,7 +224,6 @@ def test_column_set_unequal_length_object_by_mask(): gsr.__setitem__, ([mask, replace_data_2], {}), ([mask, replace_data_2], {}), - compare_error_message=False, ) @@ -239,9 +237,6 @@ def test_categorical_setitem_invalid(): rfunc=gs.__setitem__, lfunc_args_and_kwargs=([0, 5], {}), rfunc_args_and_kwargs=([0, 5], {}), - compare_error_message=False, - expected_error_message="Cannot setitem on a Categorical with a " - "new category, set the categories first", ) else: # Following workaround is needed because: diff --git a/python/cudf/cudf/tests/test_sorting.py b/python/cudf/cudf/tests/test_sorting.py index 68a56729c5a..cd0c3bc8806 100644 --- a/python/cudf/cudf/tests/test_sorting.py +++ b/python/cudf/cudf/tests/test_sorting.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. import string from itertools import product @@ -129,7 +129,6 @@ def test_series_nlargest(data, n): rfunc=sr.nlargest, lfunc_args_and_kwargs=([], {"n": 3, "keep": "what"}), rfunc_args_and_kwargs=([], {"n": 3, "keep": "what"}), - expected_error_message='keep must be either "first", "last"', ) @@ -150,7 +149,6 @@ def test_series_nsmallest(data, n): rfunc=sr.nsmallest, lfunc_args_and_kwargs=([], {"n": 3, "keep": "what"}), rfunc_args_and_kwargs=([], {"n": 3, "keep": "what"}), - expected_error_message='keep must be either "first", "last"', ) diff --git a/python/cudf/cudf/tests/test_stats.py b/python/cudf/cudf/tests/test_stats.py index 5861f67919b..715d17169a6 100644 --- a/python/cudf/cudf/tests/test_stats.py +++ b/python/cudf/cudf/tests/test_stats.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. from concurrent.futures import ThreadPoolExecutor @@ -575,7 +575,6 @@ def test_cov_corr_invalid_dtypes(gsr): rfunc=gsr.corr, lfunc_args_and_kwargs=([psr],), rfunc_args_and_kwargs=([gsr],), - compare_error_message=False, ) assert_exceptions_equal( @@ -583,7 +582,6 @@ def test_cov_corr_invalid_dtypes(gsr): rfunc=gsr.cov, lfunc_args_and_kwargs=([psr],), rfunc_args_and_kwargs=([gsr],), - compare_error_message=False, ) diff --git a/python/cudf/cudf/tests/test_string.py b/python/cudf/cudf/tests/test_string.py index 8939fcfeed9..5e073197309 100644 --- a/python/cudf/cudf/tests/test_string.py +++ b/python/cudf/cudf/tests/test_string.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2022, NVIDIA CORPORATION. +# Copyright (c) 2018-2023, NVIDIA CORPORATION. import json import re @@ -2033,18 +2033,12 @@ def test_string_starts_ends(data, pat): rfunc=gs.str.startswith, lfunc_args_and_kwargs=([pat],), rfunc_args_and_kwargs=([pat],), - compare_error_message=False, - expected_error_message="expected a string or a sequence-like " - "object, not NoneType", ) assert_exceptions_equal( lfunc=ps.str.endswith, rfunc=gs.str.endswith, lfunc_args_and_kwargs=([pat],), rfunc_args_and_kwargs=([pat],), - compare_error_message=False, - expected_error_message="expected a string or a sequence-like " - "object, not NoneType", ) else: assert_eq( @@ -2607,7 +2601,6 @@ def test_string_typecast_error(data, obj_type, dtype): rfunc=gsr.astype, lfunc_args_and_kwargs=([dtype],), rfunc_args_and_kwargs=([dtype],), - compare_error_message=False, ) @@ -3000,9 +2993,6 @@ def test_string_product(): assert_exceptions_equal( lfunc=psr.product, rfunc=sr.product, - expected_error_message=re.escape( - f"cannot perform product with type {sr.dtype}" - ), ) @@ -3010,18 +3000,14 @@ def test_string_var(): psr = pd.Series(["1", "2", "3", "4", "5"]) sr = cudf.Series(["1", "2", "3", "4", "5"]) - assert_exceptions_equal( - lfunc=psr.var, rfunc=sr.var, compare_error_message=False - ) + assert_exceptions_equal(lfunc=psr.var, rfunc=sr.var) def test_string_std(): psr = pd.Series(["1", "2", "3", "4", "5"]) sr = cudf.Series(["1", "2", "3", "4", "5"]) - assert_exceptions_equal( - lfunc=psr.std, rfunc=sr.std, compare_error_message=False - ) + assert_exceptions_equal(lfunc=psr.std, rfunc=sr.std) def test_string_slice_with_mask(): diff --git a/python/cudf/cudf/tests/test_timedelta.py b/python/cudf/cudf/tests/test_timedelta.py index b3dfafa3cd0..b4d014c9949 100644 --- a/python/cudf/cudf/tests/test_timedelta.py +++ b/python/cudf/cudf/tests/test_timedelta.py @@ -1,8 +1,7 @@ -# Copyright (c) 2020-2022, NVIDIA CORPORATION. +# Copyright (c) 2020-2023, NVIDIA CORPORATION. import datetime import operator -import re import cupy as cp import numpy as np @@ -346,7 +345,6 @@ def test_timedelta_ops_datetime_inputs( rfunc=operator.sub, lfunc_args_and_kwargs=([psr_timedelta, psr_datetime],), rfunc_args_and_kwargs=([gsr_timedelta, gsr_datetime],), - compare_error_message=False, ) @@ -1260,7 +1258,6 @@ def test_timedelta_invalid_ops(): rfunc=operator.add, lfunc_args_and_kwargs=([psr, 1],), rfunc_args_and_kwargs=([sr, 1],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1268,7 +1265,6 @@ def test_timedelta_invalid_ops(): rfunc=operator.add, lfunc_args_and_kwargs=([psr, "a"],), rfunc_args_and_kwargs=([sr, "a"],), - compare_error_message=False, ) dt_sr = cudf.Series([1, 2, 3], dtype="datetime64[ns]") @@ -1279,7 +1275,6 @@ def test_timedelta_invalid_ops(): rfunc=operator.mod, lfunc_args_and_kwargs=([psr, dt_psr],), rfunc_args_and_kwargs=([sr, dt_sr],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1288,7 +1283,6 @@ def test_timedelta_invalid_ops(): lfunc_args_and_kwargs=([psr, "a"],), rfunc_args_and_kwargs=([sr, "a"],), check_exception_type=False, - compare_error_message=False, ) assert_exceptions_equal( @@ -1296,7 +1290,6 @@ def test_timedelta_invalid_ops(): rfunc=operator.gt, lfunc_args_and_kwargs=([psr, dt_psr],), rfunc_args_and_kwargs=([sr, dt_sr],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1304,7 +1297,6 @@ def test_timedelta_invalid_ops(): rfunc=operator.lt, lfunc_args_and_kwargs=([psr, dt_psr],), rfunc_args_and_kwargs=([sr, dt_sr],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1312,7 +1304,6 @@ def test_timedelta_invalid_ops(): rfunc=operator.ge, lfunc_args_and_kwargs=([psr, dt_psr],), rfunc_args_and_kwargs=([sr, dt_sr],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1320,7 +1311,6 @@ def test_timedelta_invalid_ops(): rfunc=operator.le, lfunc_args_and_kwargs=([psr, dt_psr],), rfunc_args_and_kwargs=([sr, dt_sr],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1328,7 +1318,6 @@ def test_timedelta_invalid_ops(): rfunc=operator.truediv, lfunc_args_and_kwargs=([psr, dt_psr],), rfunc_args_and_kwargs=([sr, dt_sr],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1336,7 +1325,6 @@ def test_timedelta_invalid_ops(): rfunc=operator.floordiv, lfunc_args_and_kwargs=([psr, dt_psr],), rfunc_args_and_kwargs=([sr, dt_sr],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1344,7 +1332,6 @@ def test_timedelta_invalid_ops(): rfunc=operator.mul, lfunc_args_and_kwargs=([psr, dt_psr],), rfunc_args_and_kwargs=([sr, dt_sr],), - compare_error_message=False, ) assert_exceptions_equal( @@ -1353,7 +1340,6 @@ def test_timedelta_invalid_ops(): lfunc_args_and_kwargs=([psr, psr],), rfunc_args_and_kwargs=([sr, sr],), check_exception_type=False, - compare_error_message=False, ) assert_exceptions_equal( @@ -1361,7 +1347,6 @@ def test_timedelta_invalid_ops(): rfunc=operator.xor, lfunc_args_and_kwargs=([psr, psr],), rfunc_args_and_kwargs=([sr, sr],), - compare_error_message=False, ) @@ -1374,9 +1359,6 @@ def test_timedelta_datetime_cast_invalid(): sr.astype, (["datetime64[ns]"],), (["datetime64[ns]"],), - expected_error_message=re.escape( - "cannot astype a timedelta from timedelta64[ns] to datetime64[ns]" - ), ) sr = cudf.Series([1, 2, 3], dtype="datetime64[ns]") @@ -1387,10 +1369,6 @@ def test_timedelta_datetime_cast_invalid(): sr.astype, (["timedelta64[ns]"],), (["timedelta64[ns]"],), - expected_error_message=re.escape( - "cannot astype a datetimelike from " - "datetime64[ns] to timedelta64[ns]" - ), )