Skip to content

Commit

Permalink
FEAT-modin-project#6784: implement 'DataFrame.__rdivmod__/__divmod__'
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoly Myachev <anatoly.myachev@intel.com>
  • Loading branch information
anmyachev committed Nov 30, 2023
1 parent 76d741b commit 959b4e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions modin/pandas/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
cast_function_modin2pandas,
from_non_pandas,
from_pandas,
_doc_binary_op,
)


Expand Down Expand Up @@ -2720,6 +2721,23 @@ def __delitem__(self, key):
raise KeyError(key)
self._update_inplace(new_query_compiler=self._query_compiler.delitem(key))

@_doc_binary_op(
operation="integer division and modulo",
bin_op="divmod",
returns="tuple of two DataFrames",
)
def __divmod__(self, right):
return self._default_to_pandas(pandas.DataFrame.__divmod__, right)

@_doc_binary_op(
operation="integer division and modulo",
bin_op="divmod",
right="left",
returns="tuple of two DataFrames",
)
def __rdivmod__(self, left):
return self._default_to_pandas(pandas.DataFrame.__rdivmod__, left)

__add__ = add
__iadd__ = add # pragma: no cover
__radd__ = radd
Expand Down
9 changes: 9 additions & 0 deletions modin/pandas/test/dataframe/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ def test_math_functions(other, axis, op):
)


@pytest.mark.parametrize("other", [lambda df: 2, lambda df: df])
def test___divmod__(other):
data = test_data["float_nan_data"]

eval_general(*create_test_dfs(data), lambda df: divmod(df, other(df)))
# test __rdivmod__
eval_general(*create_test_dfs(data), lambda df: divmod(other(df), df))


@pytest.mark.parametrize(
"other",
[lambda df: df[: -(2**4)], lambda df: df[df.columns[0]].reset_index(drop=True)],
Expand Down

0 comments on commit 959b4e0

Please sign in to comment.