Skip to content

Commit

Permalink
TEST-modin-project#2288: addressing review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Myskov <[email protected]>
  • Loading branch information
amyskov committed Oct 28, 2020
1 parent 1adcb83 commit a0af8c6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 58 deletions.
55 changes: 1 addition & 54 deletions modin/pandas/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
json_short_bytes,
json_long_string,
json_long_bytes,
eval_general,
random_state,
eval_io,
)

from modin.config import Engine, Backend
Expand Down Expand Up @@ -66,59 +66,6 @@
if not os.path.exists(test_data_dir):
os.mkdir(test_data_dir)

# raising of this exceptions can be caused by unexpected behavior
# of test, but can passed by eval_io function since the type
# of this exceptions are the same
io_ops_bad_exc = [TypeError, FileNotFoundError]


def eval_io(
fn_name,
comparator=df_equals,
cast_to_str=False,
check_exception_type=True,
nonacceptable_exception_types=io_ops_bad_exc,
*args,
**kwargs,
):
"""Evaluate I/O operation outputs equality check.
Parameters
----------
fn_name: str
I/O operation name ("read_csv" for example).
comparator: obj
Function to perform comparison.
cast_to_str: bool
There could be some missmatches in dtypes, so we're
casting the whole frame to `str` before comparison.
See issue #1931 for details.
check_exception_type: bool, Exception or list of Exceptions
Check or not exception types in the case of operation fail
(compare exceptions types raised by Pandas and Modin).
If `check_exception_type` provided as Exception or list
of Exception eval_io will be passed only if occured exception
type in the `check_exception_type`.
nonacceptable_exception_types: Exception or list of Exceptions
Exceptions types that are prohibited.
"""

def applyier(module, *args, **kwargs):
result = getattr(module, fn_name)(*args, **kwargs)
if cast_to_str:
result = result.astype(str)
return result

eval_general(
pd,
pandas,
applyier,
check_exception_type=check_exception_type,
nonacceptable_exception_types=nonacceptable_exception_types,
*args,
**kwargs,
)


@pytest.fixture
def make_parquet_file():
Expand Down
61 changes: 57 additions & 4 deletions modin/pandas/test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@
"utf_8_sig",
]

# raising of this exceptions can be caused by unexpected behavior
# of I/O operation test, but can passed by eval_io function since
# the type of this exceptions are the same
io_ops_bad_exc = [TypeError, FileNotFoundError]


def categories_equals(left, right):
assert (left.ordered and right.ordered) or (not left.ordered and not right.ordered)
Expand Down Expand Up @@ -633,7 +638,7 @@ def eval_general(
nonacceptable_exception_types=None,
**kwargs,
):
if nonacceptable_exception_types not in (None, False):
if not nonacceptable_exception_types:
assert (
check_exception_type
), "check_exception_type == False, so nonacceptable_exception_types parameters are not used"
Expand All @@ -655,11 +660,11 @@ def execute_callable(fn, inplace=False, md_kwargs={}, pd_kwargs={}):
):
assert isinstance(
md_e.value, check_exception_type
), "exception type not in the list of acceptable exception types"
if nonacceptable_exception_types is not None:
), f"acceptable exception types are {check_exception_type}, actually raised {md_e.value}"
if nonacceptable_exception_types:
assert not isinstance(
md_e.value, tuple(nonacceptable_exception_types)
), "not acceptable exception type"
), f"not acceptable exception type: {md_e.value}"
else:
md_result = fn(modin_df, **md_kwargs)
return (md_result, pd_result) if not __inplace__ else (modin_df, pandas_df)
Expand All @@ -685,6 +690,54 @@ def execute_callable(fn, inplace=False, md_kwargs={}, pd_kwargs={}):
comparator(*values)


def eval_io(
fn_name,
comparator=df_equals,
cast_to_str=False,
check_exception_type=True,
nonacceptable_exception_types=io_ops_bad_exc,
*args,
**kwargs,
):
"""Evaluate I/O operation outputs equality check.
Parameters
----------
fn_name: str
I/O operation name ("read_csv" for example).
comparator: obj
Function to perform comparison.
cast_to_str: bool
There could be some missmatches in dtypes, so we're
casting the whole frame to `str` before comparison.
See issue #1931 for details.
check_exception_type: bool, Exception or list of Exceptions
Check or not exception types in the case of operation fail
(compare exceptions types raised by Pandas and Modin).
If `check_exception_type` provided as Exception or list
of Exception eval_io will be passed only if occured exception
type in the `check_exception_type`.
nonacceptable_exception_types: Exception or list of Exceptions
Exceptions types that are prohibited.
"""

def applyier(module, *args, **kwargs):
result = getattr(module, fn_name)(*args, **kwargs)
if cast_to_str:
result = result.astype(str)
return result

eval_general(
pd,
pandas,
applyier,
check_exception_type=check_exception_type,
nonacceptable_exception_types=nonacceptable_exception_types,
*args,
**kwargs,
)


def create_test_dfs(*args, **kwargs):
return pd.DataFrame(*args, **kwargs), pandas.DataFrame(*args, **kwargs)

Expand Down

0 comments on commit a0af8c6

Please sign in to comment.