Skip to content

Commit

Permalink
REFACTOR-modin-project#7008: Remove 'check_exception_type' argument o…
Browse files Browse the repository at this point in the history
…f 'eval_general' function

Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
  • Loading branch information
anmyachev committed Mar 5, 2024
1 parent 5769a1d commit 75aec40
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ def test_read_csv_datetime(
eval_io(
fn_name="read_csv",
md_extra_kwargs={"engine": engine},
check_exception_type=not skip_exc_type_check,
raising_exceptions=None if skip_exc_type_check else io_ops_bad_exc,
# read_csv kwargs
filepath_or_buffer=pytest.csvs_names["test_read_csv_regular"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def eval_io(
fn_name,
comparator=df_equals,
cast_to_str=False,
check_exception_type=True,
raising_exceptions=io_ops_bad_exc,
check_kwargs_callable=True,
modin_warning=None,
Expand Down Expand Up @@ -75,7 +74,6 @@ def hdk_comparator(df1, df2, **kwargs):
fn_name,
comparator=hdk_comparator,
cast_to_str=cast_to_str,
check_exception_type=check_exception_type,
raising_exceptions=raising_exceptions,
check_kwargs_callable=check_kwargs_callable,
modin_warning=modin_warning,
Expand Down
2 changes: 0 additions & 2 deletions modin/pandas/test/dataframe/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ def test_pivot(data, index, columns, values):
index=index,
columns=columns,
values=values,
check_exception_type=None,
)


Expand Down Expand Up @@ -660,7 +659,6 @@ def test_pivot_table_data(data, index, columns, values, aggfunc):
columns=columns,
values=values,
aggfunc=aggfunc,
check_exception_type=None,
)


Expand Down
1 change: 0 additions & 1 deletion modin/pandas/test/dataframe/test_map_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ def test_astype():
if isinstance(df, pd.DataFrame)
else pandas.Series([str, str], index=["col1", "col1"])
),
check_exception_type=True,
)


Expand Down
4 changes: 0 additions & 4 deletions modin/pandas/test/dataframe/test_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,6 @@ def comparator(md_res, pd_res):
ascending=ascending,
),
comparator=comparator,
# Modin's `sort_values` does not validate `ascending` type and so
# does not raise an exception when it isn't a bool, when pandas do so,
# visit modin-issue#3388 for more info.
check_exception_type=None if sort and ascending is None else True,
)


Expand Down
6 changes: 1 addition & 5 deletions modin/pandas/test/dataframe/test_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def test_agg_apply(axis, func, op):
eval_general(
*create_test_dfs(test_data["float_nan_data"]),
lambda df: getattr(df, op)(func, axis),
check_exception_type=True,
)


Expand All @@ -95,7 +94,6 @@ def test_agg_apply_axis_names(axis, func, op):
eval_general(
*create_test_dfs(test_data["int_data"]),
lambda df: getattr(df, op)(func, axis),
check_exception_type=True,
)


Expand Down Expand Up @@ -521,6 +519,4 @@ def test_query_with_element_access_issue_4580(engine):
ids=agg_func_keys + agg_func_except_keys,
)
def test_transform(data, func):
eval_general(
*create_test_dfs(data), lambda df: df.transform(func), check_exception_type=True
)
eval_general(*create_test_dfs(data), lambda df: df.transform(func))
46 changes: 14 additions & 32 deletions modin/pandas/test/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ def test_mixed_dtypes_groupby(as_index):
]
for func in agg_functions:
eval_agg(modin_groupby, pandas_groupby, func)
eval_aggregate(modin_groupby, pandas_groupby, func)

eval_general(modin_groupby, pandas_groupby, lambda df: df.last())
eval_max(modin_groupby, pandas_groupby)
Expand Down Expand Up @@ -569,21 +568,14 @@ def maybe_get_columns(df, by):
for func in agg_functions:
# Pandas raises an exception when 'by' contains categorical key and `as_index=False`
# because of this bug: https://github.com/pandas-dev/pandas/issues/36698
# Modin correctly processes the result, that's why `check_exception_type=None` in some cases
# Modin correctly processes the result
is_pandas_bug_case = not as_index and col1_category and isinstance(func, dict)

eval_general(
modin_groupby,
pandas_groupby,
lambda grp: grp.agg(func),
check_exception_type=None if is_pandas_bug_case else True,
)
eval_general(
modin_groupby,
pandas_groupby,
lambda grp: grp.aggregate(func),
check_exception_type=None if is_pandas_bug_case else True,
)
if not is_pandas_bug_case:
eval_general(
modin_groupby,
pandas_groupby,
lambda grp: grp.agg(func),
)

eval_general(modin_groupby, pandas_groupby, lambda df: df.last())
eval_general(modin_groupby, pandas_groupby, lambda df: df.rank())
Expand All @@ -599,13 +591,13 @@ def maybe_get_columns(df, by):
eval_ngroup(modin_groupby, pandas_groupby)
# Pandas raising exception when 'by' contains categorical key and `as_index=False`
# because of a bug: https://github.com/pandas-dev/pandas/issues/36698
# Modin correctly processes the result, so that's why `check_exception_type=None` in some cases
eval_general(
modin_groupby,
pandas_groupby,
lambda df: df.nunique(),
check_exception_type=None if (col1_category and not as_index) else True,
)
# Modin correctly processes the result
if not (col1_category and not as_index):
eval_general(
modin_groupby,
pandas_groupby,
lambda df: df.nunique(),
)
# TypeError: category type does not support median operations
eval_general(
modin_groupby,
Expand All @@ -630,7 +622,6 @@ def maybe_get_columns(df, by):
modin_groupby,
pandas_groupby,
lambda df: df.transform(func),
check_exception_type=None,
)

pipe_functions = [lambda dfgb: dfgb.sum()]
Expand All @@ -655,7 +646,6 @@ def maybe_get_columns(df, by):
modin_groupby,
pandas_groupby,
lambda df: df.size(),
check_exception_type=None,
)
eval_general(modin_groupby, pandas_groupby, lambda df: df.tail(n))
eval_quantile(modin_groupby, pandas_groupby)
Expand Down Expand Up @@ -771,7 +761,6 @@ def test_single_group_row_groupby():
]
for func in agg_functions:
eval_agg(modin_groupby, pandas_groupby, func)
eval_aggregate(modin_groupby, pandas_groupby, func)

eval_general(modin_groupby, pandas_groupby, lambda df: df.last())
eval_rank(modin_groupby, pandas_groupby)
Expand Down Expand Up @@ -900,7 +889,6 @@ def test_large_row_groupby(is_by_category):
]
for func in agg_functions:
eval_agg(modin_groupby, pandas_groupby, func)
eval_aggregate(modin_groupby, pandas_groupby, func)

eval_general(modin_groupby, pandas_groupby, lambda df: df.last())
eval_rank(modin_groupby, pandas_groupby)
Expand Down Expand Up @@ -1157,7 +1145,6 @@ def test_series_groupby(by, as_index_series_or_dataframe):
]
for func in agg_functions:
eval_agg(modin_groupby, pandas_groupby, func)
eval_aggregate(modin_groupby, pandas_groupby, func)

eval_general(modin_groupby, pandas_groupby, lambda df: df.last())
eval_rank(modin_groupby, pandas_groupby)
Expand Down Expand Up @@ -1322,10 +1309,6 @@ def eval_std(modin_groupby, pandas_groupby, numeric_only=False):
)


def eval_aggregate(modin_groupby, pandas_groupby, func):
df_equals(modin_groupby.aggregate(func), pandas_groupby.aggregate(func))


def eval_agg(modin_groupby, pandas_groupby, func):
df_equals(modin_groupby.agg(func), pandas_groupby.agg(func))

Expand Down Expand Up @@ -2648,7 +2631,6 @@ def run_test(eval_function, *args, **kwargs):
run_test(eval___getattr__, item="b")
run_test(eval___getitem__, item="b")
run_test(eval_agg, func=lambda df: df.mean())
run_test(eval_aggregate, func=lambda df: df.mean())
run_test(eval_any)
run_test(eval_apply, func=lambda df: df.mean())
run_test(eval_count)
Expand Down
8 changes: 0 additions & 8 deletions modin/pandas/test/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3646,10 +3646,6 @@ def sort_sensitive_comparator(df1, df2):
ascending=ascending,
),
comparator=sort_sensitive_comparator,
# Modin's `sort_values` does not validate `ascending` type and so
# does not raise an exception when it isn't a bool, when pandas do so,
# visit modin-issue#3388 for more info.
check_exception_type=None if sort and ascending is None else True,
)

# from issue #2365
Expand All @@ -3665,10 +3661,6 @@ def sort_sensitive_comparator(df1, df2):
ascending=ascending,
),
comparator=sort_sensitive_comparator,
# Modin's `sort_values` does not validate `ascending` type and so
# does not raise an exception when it isn't a bool, when pandas do so,
# visit modin-issue#3388 for more info.
check_exception_type=None if sort and ascending is None else True,
)


Expand Down
34 changes: 10 additions & 24 deletions modin/pandas/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,25 +874,18 @@ def eval_general(
operation,
comparator=df_equals,
__inplace__=False,
check_exception_type=True,
raising_exceptions=None,
check_kwargs_callable=True,
md_extra_kwargs=None,
comparator_kwargs=None,
**kwargs,
):
if raising_exceptions:
assert (
check_exception_type
), "if raising_exceptions is not None or False, check_exception_type should be True"
md_kwargs, pd_kwargs = {}, {}

def execute_callable(fn, inplace=False, md_kwargs={}, pd_kwargs={}):
try:
pd_result = fn(pandas_df, **pd_kwargs)
except Exception as pd_e:
if check_exception_type is None:
return None
try:
if inplace:
_ = fn(modin_df, **md_kwargs)
Expand All @@ -902,16 +895,15 @@ def execute_callable(fn, inplace=False, md_kwargs={}, pd_kwargs={}):
fn(modin_df, **md_kwargs)
) # force materialization
except Exception as md_e:
if check_exception_type:
assert isinstance(
md_e, type(pd_e)
), "Got Modin Exception type {}, but pandas Exception type {} was expected".format(
type(md_e), type(pd_e)
)
if raising_exceptions:
assert not isinstance(
md_e, tuple(raising_exceptions)
), f"not acceptable exception type: {md_e}"
assert isinstance(
md_e, type(pd_e)
), "Got Modin Exception type {}, but pandas Exception type {} was expected".format(
type(md_e), type(pd_e)
)
if raising_exceptions:
assert not isinstance(
md_e, tuple(raising_exceptions)
), f"not acceptable exception type: {md_e}"
else:
raise NoModinException(
f"Modin doesn't throw an exception, while pandas does: [{repr(pd_e)}]"
Expand Down Expand Up @@ -949,7 +941,6 @@ def eval_io(
fn_name,
comparator=df_equals,
cast_to_str=False,
check_exception_type=True,
raising_exceptions=io_ops_bad_exc,
check_kwargs_callable=True,
modin_warning=None,
Expand All @@ -970,13 +961,9 @@ def eval_io(
There could be some mismatches in dtypes, so we're
casting the whole frame to `str` before comparison.
See issue #1931 for details.
check_exception_type: bool
Check or not exception types in the case of operation fail
(compare exceptions types raised by Pandas and Modin).
raising_exceptions: Exception or list of Exceptions
Exceptions that should be raised even if they are raised
both by Pandas and Modin (check evaluated only if
`check_exception_type` passed as `True`).
both by Pandas and Modin.
modin_warning: obj
Warning that should be raised by Modin.
modin_warning_str_match: str
Expand All @@ -997,7 +984,6 @@ def call_eval_general():
pandas,
applyier,
comparator=comparator,
check_exception_type=check_exception_type,
raising_exceptions=raising_exceptions,
check_kwargs_callable=check_kwargs_callable,
md_extra_kwargs=md_extra_kwargs,
Expand Down

0 comments on commit 75aec40

Please sign in to comment.