Skip to content

Commit

Permalink
FEAT-modin-project#1611: Add mod operation
Browse files Browse the repository at this point in the history
Signed-off-by: Alina <alina.bykovskaya@intel.com>
  • Loading branch information
abykovsk committed Feb 11, 2021
1 parent 569337b commit 87611c5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 3 additions & 0 deletions modin/experimental/backends/omnisci/query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ def sub(self, other, **kwargs):
def mul(self, other, **kwargs):
return self._bin_op(other, "mul", **kwargs)

def mod(self, other, **kwargs):
return self._bin_op(other, "mod", **kwargs)

def floordiv(self, other, **kwargs):
return self._bin_op(other, "floordiv", **kwargs)

Expand Down
6 changes: 5 additions & 1 deletion modin/experimental/engines/omnisci_on_ray/frame/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class BaseExpr(abc.ABC):
"add": "+",
"sub": "-",
"mul": "*",
"mod": "MOD",
"floordiv": "/",
"truediv": "/",
"pow": "POWER",
Expand All @@ -74,7 +75,7 @@ class BaseExpr(abc.ABC):
"ne": "<>",
}

preserve_dtype_math_ops = {"add", "sub", "mul", "floordiv", "pow"}
preserve_dtype_math_ops = {"add", "sub", "mul", "mod", "floordiv", "pow"}
promote_to_float_math_ops = {"truediv"}

def eq(self, other):
Expand Down Expand Up @@ -128,6 +129,9 @@ def sub(self, other):
def mul(self, other):
return self.bin_op(other, "mul")

def mod(self, other):
return self.bin_op(other, "mod")

def truediv(self, other):
return self.bin_op(other, "truediv")

Expand Down
33 changes: 33 additions & 0 deletions modin/experimental/engines/omnisci_on_ray/test/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,39 @@ def mul2(lib, df):
run_and_compare(mul1, data=self.data)
run_and_compare(mul2, data=self.data)

def test_mod_cst(self):
def mod(lib, df):
return df % 2

run_and_compare(mod, data=self.data)

def test_mod_list(self):
def mod(lib, df):
return df % [2, 3, 4, 5]

run_and_compare(mod, data=self.data)

@pytest.mark.parametrize("fill_value", fill_values)
def test_mod_method_columns(self, fill_value):
def mod1(lib, df, fill_value):
return df["a"].mod(df["b"], fill_value=fill_value)

def mod2(lib, df, fill_value):
return df[["a", "c"]].mod(df[["b", "a"]], fill_value=fill_value)

run_and_compare(mod1, data=self.data, fill_value=fill_value)
run_and_compare(mod2, data=self.data, fill_value=fill_value)

def test_mod_columns(self):
def mod1(lib, df):
return df["a"] % df["b"]

def mod2(lib, df):
return df[["a", "c"]] % df[["b", "a"]]

run_and_compare(mod1, data=self.data)
run_and_compare(mod2, data=self.data)

def test_truediv_cst(self):
def truediv(lib, df):
return df / 2
Expand Down

0 comments on commit 87611c5

Please sign in to comment.