Skip to content

Commit

Permalink
PR changes
Browse files Browse the repository at this point in the history
Signed-off-by: arunjose696 <arunjose696@gmail.com>
  • Loading branch information
arunjose696 committed Aug 28, 2024
1 parent cac89d2 commit af0a7ba
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 102 deletions.
3 changes: 1 addition & 2 deletions modin/core/storage_formats/pandas/native_query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
from pandas.core.dtypes.common import is_list_like, is_scalar

from modin.core.storage_formats.base.query_compiler import BaseQueryCompiler
from modin.core.storage_formats.base.query_compiler_caster import QueryCompilerCaster
from modin.utils import (
MODIN_UNNAMED_SERIES_LABEL,
_inherit_docstrings,
try_cast_to_pandas,
)

from .query_compiler_validator import QueryCompilerCaster


def _get_axis(axis):
"""
Expand Down
2 changes: 1 addition & 1 deletion modin/core/storage_formats/pandas/query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
extract_dtype,
)
from modin.core.storage_formats import BaseQueryCompiler
from modin.core.storage_formats.base.query_compiler_caster import QueryCompilerCaster
from modin.error_message import ErrorMessage
from modin.logging import get_logger
from modin.utils import (
Expand All @@ -79,7 +80,6 @@
from .aggregations import CorrCovBuilder
from .groupby import GroupbyReduceImpl, PivotTableImpl
from .merge import MergeImpl
from .query_compiler_validator import QueryCompilerCaster
from .utils import get_group_names, merge_partitioning

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def decorator(obj: Fn) -> Fn:
# This is required because inspect converts class methods to member functions
current_class_attrs = vars(obj)
for key in current_class_attrs:
if key in current_class_attrs:
all_attrs[key] = current_class_attrs[key]
all_attrs[key] = current_class_attrs[key]

for attr_name, attr_value in all_attrs.items():
if isinstance(
Expand Down
2 changes: 1 addition & 1 deletion modin/tests/pandas/native_df_mode/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import pytest

from modin.config import NativeDataframeMode, NPartitions
from modin.tests.pandas.native_df_mode.utils import eval_general_interop
from modin.tests.pandas.utils import (
create_test_dfs,
default_to_pandas_ignore_string,
df_equals,
eval_general_interop,
test_data,
test_data_keys,
test_data_values,
Expand Down
2 changes: 1 addition & 1 deletion modin/tests/pandas/native_df_mode/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import modin.pandas as pd
from modin.config import NativeDataframeMode, NPartitions
from modin.pandas.io import to_pandas
from modin.tests.pandas.native_df_mode.utils import eval_general_interop
from modin.tests.pandas.utils import (
create_test_dfs,
create_test_series,
default_to_pandas_ignore_string,
df_equals,
eval_general_interop,
test_data,
test_data_diff_dtype,
test_data_keys,
Expand Down
2 changes: 1 addition & 1 deletion modin/tests/pandas/native_df_mode/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import modin.pandas as pd
from modin.config import NativeDataframeMode, NPartitions
from modin.tests.pandas.native_df_mode.utils import eval_general_interop
from modin.tests.pandas.utils import (
RAND_HIGH,
RAND_LOW,
Expand All @@ -27,7 +28,6 @@
default_to_pandas_ignore_string,
df_equals,
eval_general,
eval_general_interop,
test_data,
test_data_keys,
test_data_values,
Expand Down
2 changes: 1 addition & 1 deletion modin/tests/pandas/native_df_mode/test_join_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import modin.pandas as pd
from modin.config import NativeDataframeMode, NPartitions
from modin.pandas.io import to_pandas
from modin.tests.pandas.native_df_mode.utils import eval_general_interop
from modin.tests.pandas.utils import (
create_test_dfs,
create_test_series,
default_to_pandas_ignore_string,
df_equals,
eval_general,
eval_general_interop,
random_state,
test_data_keys,
test_data_values,
Expand Down
108 changes: 108 additions & 0 deletions modin/tests/pandas/native_df_mode/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Licensed to Modin Development Team under one or more contributor license agreements.
# See the NOTICE file distributed with this work for additional information regarding
# copyright ownership. The Modin Development Team licenses this file to you under the
# Apache License, Version 2.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
from modin.config import Engine
from modin.tests.pandas.utils import NoModinException, create_test_dfs, df_equals
from modin.utils import try_cast_to_pandas


def eval_general_interop(
data,
backend,
operation,
df_mode_pair,
comparator=df_equals,
__inplace__=False,
expected_exception=None,
check_kwargs_callable=True,
md_extra_kwargs=None,
comparator_kwargs=None,
**kwargs,
):
df_mode1, df_mode2 = df_mode_pair
modin_df1, pandas_df1 = create_test_dfs(data, backend=backend, df_mode=df_mode1)
modin_df2, pandas_df2 = create_test_dfs(data, backend=backend, df_mode=df_mode2)
md_kwargs, pd_kwargs = {}, {}

def execute_callable(fn, inplace=False, md_kwargs={}, pd_kwargs={}):

Check notice

Code scanning / CodeQL

Explicit returns mixed with implicit (fall through) returns Note test

Mixing implicit and explicit returns may indicate an error as implicit returns always return None.
try:
pd_result = fn(pandas_df1, pandas_df2, **pd_kwargs)
except Exception as pd_e:
try:
if inplace:
_ = fn(modin_df1, modin_df2, **md_kwargs)
try_cast_to_pandas(modin_df1) # force materialization
else:
try_cast_to_pandas(
fn(modin_df1, modin_df2, **md_kwargs)
) # force materialization
except Exception as 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 expected_exception:
if Engine.get() == "Ray":
from ray.exceptions import RayTaskError

# unwrap ray exceptions from remote worker
if isinstance(md_e, RayTaskError):
md_e = md_e.args[0]
assert (
type(md_e) is type(expected_exception)
and md_e.args == expected_exception.args
), f"not acceptable Modin's exception: [{repr(md_e)}]"
assert (
pd_e.args == expected_exception.args
), f"not acceptable Pandas' exception: [{repr(pd_e)}]"
elif expected_exception is False:
# The only way to disable exception message checking.
pass
else:
# It’s not enough that Modin and pandas have the same types of exceptions;
# we need to explicitly specify the instance of an exception
# (using `expected_exception`) in tests so that we can check exception messages.
# This allows us to eliminate situations where exceptions are thrown
# that we don't expect, which could hide different bugs.
raise pd_e
else:
raise NoModinException(
f"Modin doesn't throw an exception, while pandas does: [{repr(pd_e)}]"
)
else:
md_result = fn(modin_df1, modin_df2, **md_kwargs)
return (md_result, pd_result) if not inplace else (modin_df1, pandas_df1)

for key, value in kwargs.items():
if check_kwargs_callable and callable(value):
values = execute_callable(value)
# that means, that callable raised an exception
if values is None:
return
else:
md_value, pd_value = values
else:
md_value, pd_value = value, value

md_kwargs[key] = md_value
pd_kwargs[key] = pd_value

if md_extra_kwargs:
assert isinstance(md_extra_kwargs, dict)
md_kwargs.update(md_extra_kwargs)

values = execute_callable(
operation, md_kwargs=md_kwargs, pd_kwargs=pd_kwargs, inplace=__inplace__
)
if values is not None:
comparator(*values, **(comparator_kwargs or {}))
93 changes: 0 additions & 93 deletions modin/tests/pandas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,99 +915,6 @@ class NoModinException(Exception):
pass


def eval_general_interop(
data,
backend,
operation,
df_mode_pair,
comparator=df_equals,
__inplace__=False,
expected_exception=None,
check_kwargs_callable=True,
md_extra_kwargs=None,
comparator_kwargs=None,
**kwargs,
):
df_mode1, df_mode2 = df_mode_pair
modin_df1, pandas_df1 = create_test_dfs(data, backend=backend, df_mode=df_mode1)
modin_df2, pandas_df2 = create_test_dfs(data, backend=backend, df_mode=df_mode2)
md_kwargs, pd_kwargs = {}, {}

def execute_callable(fn, inplace=False, md_kwargs={}, pd_kwargs={}):
try:
pd_result = fn(pandas_df1, pandas_df2, **pd_kwargs)
except Exception as pd_e:
try:
if inplace:
_ = fn(modin_df1, modin_df2, **md_kwargs)
try_cast_to_pandas(modin_df1) # force materialization
else:
try_cast_to_pandas(
fn(modin_df1, modin_df2, **md_kwargs)
) # force materialization
except Exception as 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 expected_exception:
if Engine.get() == "Ray":
from ray.exceptions import RayTaskError

# unwrap ray exceptions from remote worker
if isinstance(md_e, RayTaskError):
md_e = md_e.args[0]
assert (
type(md_e) is type(expected_exception)
and md_e.args == expected_exception.args
), f"not acceptable Modin's exception: [{repr(md_e)}]"
assert (
pd_e.args == expected_exception.args
), f"not acceptable Pandas' exception: [{repr(pd_e)}]"
elif expected_exception is False:
# The only way to disable exception message checking.
pass
else:
# It’s not enough that Modin and pandas have the same types of exceptions;
# we need to explicitly specify the instance of an exception
# (using `expected_exception`) in tests so that we can check exception messages.
# This allows us to eliminate situations where exceptions are thrown
# that we don't expect, which could hide different bugs.
raise pd_e
else:
raise NoModinException(
f"Modin doesn't throw an exception, while pandas does: [{repr(pd_e)}]"
)
else:
md_result = fn(modin_df1, modin_df2, **md_kwargs)
return (md_result, pd_result) if not inplace else (modin_df1, pandas_df1)

for key, value in kwargs.items():
if check_kwargs_callable and callable(value):
values = execute_callable(value)
# that means, that callable raised an exception
if values is None:
return
else:
md_value, pd_value = values
else:
md_value, pd_value = value, value

md_kwargs[key] = md_value
pd_kwargs[key] = pd_value

if md_extra_kwargs:
assert isinstance(md_extra_kwargs, dict)
md_kwargs.update(md_extra_kwargs)

values = execute_callable(
operation, md_kwargs=md_kwargs, pd_kwargs=pd_kwargs, inplace=__inplace__
)
if values is not None:
comparator(*values, **(comparator_kwargs or {}))


def eval_general(
modin_df,
pandas_df,
Expand Down

0 comments on commit af0a7ba

Please sign in to comment.