Skip to content

Commit

Permalink
Separate tests of the new class.
Browse files Browse the repository at this point in the history
Signed-off-by: mvashishtha <mahesh@ponder.io>
  • Loading branch information
mvashishtha committed Nov 24, 2022
1 parent 4bcf708 commit eb44e37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions modin/pandas/test/dataframe/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,20 @@ def test_add_custom_class():
)


def test_non_commutative_multiply_pandas():
# The non commutative integer class implementation is tricky. Check that
# multiplying such an integer with a pandas dataframe is really not
# commutative.
pandas_df = pd.DataFrame([[1]], dtype=int)
integer = NonCommutativeMultiplyInteger(2)
assert not (integer * pandas_df).equals(pandas_df * integer)


def test_non_commutative_multiply():
# This test checks that mul and rmul do different things when
# multiplication is not commutative, e.g. for adding a string to a string.
# For context see https://github.com/modin-project/modin/issues/5238
modin_df, pandas_df = create_test_dfs([1], dtype=int)
integer = NonCommutativeMultiplyInteger(2)
# It's tricky to get the non commutative integer class implementation
# right, so before we do the actual test, check that the operation
# we care about is really not commmutative in pandas.
assert not (integer * pandas_df).equals(pandas_df * integer)
eval_general(modin_df, pandas_df, lambda s: integer * s)
eval_general(modin_df, pandas_df, lambda s: s * integer)
13 changes: 9 additions & 4 deletions modin/pandas/test/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4267,16 +4267,21 @@ def test_non_commutative_add_string_to_series(data):
eval_general(*create_test_series(data), lambda s: s + "string")


def test_non_commutative_multiply_pandas():
# The non commutative integer class implementation is tricky. Check that
# multiplying such an integer with a pandas series is really not
# commutative.
pandas_series = pd.DataFrame([[1]], dtype=int)
integer = NonCommutativeMultiplyInteger(2)
assert not (integer * pandas_series).equals(pandas_series * integer)


def test_non_commutative_multiply():
# This test checks that mul and rmul do different things when
# multiplication is not commutative, e.g. for adding a string to a string.
# For context see https://github.com/modin-project/modin/issues/5238
modin_series, pandas_series = create_test_series(1, dtype=int)
integer = NonCommutativeMultiplyInteger(2)
# It's tricky to get the non commutative integer class implementation
# right, so before we do the actual test, check that the operation
# we care about is really not commmutative in pandas.
assert not (integer * pandas_series).equals(pandas_series * integer)
eval_general(modin_series, pandas_series, lambda s: integer * s)
eval_general(modin_series, pandas_series, lambda s: s * integer)

Expand Down

0 comments on commit eb44e37

Please sign in to comment.