Skip to content

Commit

Permalink
FIX-#2596: Fix some binary operations
Browse files Browse the repository at this point in the history
Signed-off-by: Igoshev, Yaroslav <yaroslav.igoshev@intel.com>
  • Loading branch information
YarShev committed Jan 26, 2021
1 parent a266448 commit 9982e3a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
8 changes: 7 additions & 1 deletion modin/data_management/functions/binary_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def call(cls, func, *call_args, **call_kwds):
def caller(query_compiler, other, *args, **kwargs):
axis = kwargs.get("axis", 0)
broadcast = kwargs.pop("broadcast", False)
squeeze_self = kwargs.pop("squeeze_self", None)
join_type = call_kwds.get("join_type", "outer")
if isinstance(other, type(query_compiler)):
if broadcast:
Expand Down Expand Up @@ -57,7 +58,12 @@ def caller(query_compiler, other, *args, **kwargs):
new_columns = query_compiler.columns
new_modin_frame = query_compiler._modin_frame._apply_full_axis(
axis,
lambda df: func(df, other, *args, **kwargs),
lambda df: func(
df.squeeze(axis=1) if squeeze_self else df,
other,
*args,
**kwargs
),
new_index=query_compiler.index,
new_columns=new_columns,
)
Expand Down
11 changes: 11 additions & 0 deletions modin/pandas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ def _binary_op(self, op, other, **kwargs):
getattr(getattr(pandas, type(self).__name__), op), other, **kwargs
)
other = self._validate_other(other, axis, numeric_or_object_only=True)
exclude_list = [
"__add__",
"__and__",
"__rand__",
"__or__",
"__ror__",
"__xor__",
"__rxor__",
]
if op in exclude_list:
kwargs.pop("axis")
new_query_compiler = getattr(self._query_compiler, op)(other, **kwargs)
return self._create_or_update_from_compiler(new_query_compiler)

Expand Down
1 change: 0 additions & 1 deletion modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,6 @@ def __delitem__(self, key):
__mod__ = mod
__imod__ = mod # pragma: no cover
__rmod__ = rmod
__div__ = div
__rdiv__ = rdiv

@property
Expand Down
11 changes: 4 additions & 7 deletions modin/pandas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ def __radd__(self, left):

def __and__(self, other):
new_self, new_other = self._prepare_inter_op(other)
return super(Series, new_self).__and__(new_other)
return new_self._binary_op("__and__", new_other, axis=0, squeeze_self=True)

def __rand__(self, other):
return self._binary_op("__rand__", other, axis=0, squeeze_self=True)

def __array__(self, dtype=None):
return super(Series, self).__array__(dtype).flatten()
Expand All @@ -169,12 +172,6 @@ def __delitem__(self, key):
raise KeyError(key)
self.drop(labels=key, inplace=True)

def __div__(self, right):
return self.div(right)

def __rdiv__(self, left):
return self.rdiv(left)

def __divmod__(self, right):
return self.divmod(right)

Expand Down
2 changes: 0 additions & 2 deletions modin/pandas/test/dataframe/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ def test_math_functions_level(op):
("sub", "subtract"),
("add", "__add__"),
("radd", "__radd__"),
("div", "__div__"),
("rdiv", "__rdiv__"),
("truediv", "__truediv__"),
("rtruediv", "__rtruediv__"),
("floordiv", "__floordiv__"),
Expand Down
1 change: 1 addition & 0 deletions modin/pandas/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def test_top_level_api_equality():
except IndexError:
pass

# See pandas issue #39167 for more info
try:
assert not len(difference), "Extra params found in API: {}".format(difference)
except AssertionError:
Expand Down
6 changes: 0 additions & 6 deletions modin/pandas/test/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,6 @@ def test___delitem__(data):
df_equals(modin_series, pandas_series)


@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
def test___div__(data):
modin_series, pandas_series = create_test_series(data)
inter_df_math_helper(modin_series, pandas_series, "__div__")


@pytest.mark.parametrize("data", test_data_values, ids=test_data_keys)
def test_divmod(data):
modin_series, pandas_series = create_test_series(data)
Expand Down

0 comments on commit 9982e3a

Please sign in to comment.