Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
wjsi committed Oct 2, 2023
1 parent 0a42ba8 commit 576923b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
32 changes: 19 additions & 13 deletions mars/dataframe/merge/tests/test_merge_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,15 @@ def test_join_on(setup):
expected4.set_index("a2", inplace=True)
result4.set_index("a2", inplace=True)
pd.testing.assert_frame_equal(
sort_dataframe_inplace(expected4, 0), sort_dataframe_inplace(result4, 0)
sort_dataframe_inplace(expected4, 0, kind="mergesort"),
sort_dataframe_inplace(result4, 0, kind="mergesort"),
)


def test_merge_one_chunk(setup):
def sort_by_col1(df):
return df.sort_values(by=df.columns[1], kind="mergesort")

df1 = pd.DataFrame(
{"lkey": ["foo", "bar", "baz", "foo"], "value": [1, 2, 3, 5]},
index=["a1", "a2", "a3", "a4"],
Expand Down Expand Up @@ -348,8 +352,8 @@ def test_merge_one_chunk(setup):
result = jdf.execute().fetch()

pd.testing.assert_frame_equal(
expected.sort_values(by=expected.columns[1]).reset_index(drop=True),
result.sort_values(by=result.columns[1]).reset_index(drop=True),
sort_by_col1(expected).reset_index(drop=True),
sort_by_col1(result).reset_index(drop=True),
)

# right have one chunk
Expand All @@ -361,8 +365,8 @@ def test_merge_one_chunk(setup):
result = jdf.execute().fetch()

pd.testing.assert_frame_equal(
expected.sort_values(by=expected.columns[1]).reset_index(drop=True),
result.sort_values(by=result.columns[1]).reset_index(drop=True),
sort_by_col1(expected).reset_index(drop=True),
sort_by_col1(result).reset_index(drop=True),
)

# left have one chunk and how="left", then one chunk tile
Expand All @@ -377,8 +381,8 @@ def test_merge_one_chunk(setup):
result = jdf.execute().fetch()

pd.testing.assert_frame_equal(
expected.sort_values(by=expected.columns[1]).reset_index(drop=True),
result.sort_values(by=result.columns[1]).reset_index(drop=True),
sort_by_col1(expected).reset_index(drop=True),
sort_by_col1(result).reset_index(drop=True),
)


Expand Down Expand Up @@ -418,7 +422,8 @@ def test_broadcast_merge(setup):
expected.set_index("key", inplace=True)
result.set_index("key", inplace=True)
pd.testing.assert_frame_equal(
sort_dataframe_inplace(expected, 0), sort_dataframe_inplace(result, 0)
sort_dataframe_inplace(expected, 0, kind="mergesort"),
sort_dataframe_inplace(result, 0, kind="mergesort"),
)

# test broadcast right and how="left"
Expand All @@ -438,8 +443,8 @@ def test_broadcast_merge(setup):
expected.set_index("key", inplace=True)
result.set_index("key", inplace=True)
pd.testing.assert_frame_equal(
expected.sort_values(by=["key", "value_x"]),
result.sort_values(by=["key", "value_x"]),
expected.sort_values(by=["key", "value_x"], kind="mergesort"),
result.sort_values(by=["key", "value_x"], kind="mergesort"),
)

# test broadcast left
Expand All @@ -459,7 +464,8 @@ def test_broadcast_merge(setup):
expected.set_index("key", inplace=True)
result.set_index("key", inplace=True)
pd.testing.assert_frame_equal(
sort_dataframe_inplace(expected, 0), sort_dataframe_inplace(result, 0)
sort_dataframe_inplace(expected, 0, kind="mergesort"),
sort_dataframe_inplace(result, 0, kind="mergesort"),
)

# test broadcast left and how="right"
Expand All @@ -479,8 +485,8 @@ def test_broadcast_merge(setup):
expected.set_index("key", inplace=True)
result.set_index("key", inplace=True)
pd.testing.assert_frame_equal(
expected.sort_values(by=["key", "value_x"]),
result.sort_values(by=["key", "value_x"]),
expected.sort_values(by=["key", "value_x"], kind="mergesort"),
result.sort_values(by=["key", "value_x"], kind="mergesort"),
)


Expand Down
4 changes: 2 additions & 2 deletions mars/dataframe/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ def hash_dtypes(dtypes, size):
return [dtypes[index] for index in hashed_indexes]


def sort_dataframe_inplace(df, *axis):
def sort_dataframe_inplace(df, *axis, **kw):
for ax in axis:
df.sort_index(axis=ax, inplace=True)
df.sort_index(axis=ax, inplace=True, **kw)

Check warning on line 111 in mars/dataframe/utils.py

View check run for this annotation

Codecov / codecov/patch

mars/dataframe/utils.py#L111

Added line #L111 was not covered by tests
return df


Expand Down
1 change: 0 additions & 1 deletion mars/learn/contrib/lightgbm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import pandas as pd

from ....dataframe import DataFrame as MarsDataFrame, Series as MarsSeries
from ....lib.version import parse as parse_version
from ....tensor import tensor as mars_tensor


Expand Down
8 changes: 2 additions & 6 deletions mars/learn/contrib/lightgbm/tests/test_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ def test_local_classifier(create_cluster):
# test sparse tensor
X_sparse_data = X_sparse
classifier = LGBMClassifier(n_estimators=2)
classifier.fit(
X_sparse_data, y_data, eval_set=[(X_sparse_data, y_data)]
)
classifier.fit(X_sparse_data, y_data, eval_set=[(X_sparse_data, y_data)])
prediction = classifier.predict(X_sparse_data)

assert prediction.ndim == 1
Expand Down Expand Up @@ -118,9 +116,7 @@ def test_local_classifier(create_cluster):

# should raise error if weight.ndim > 1
with pytest.raises(ValueError):
LGBMClassifier(n_estimators=2).fit(
X, y_df, sample_weight=mt.random.rand(1, 1)
)
LGBMClassifier(n_estimators=2).fit(X, y_df, sample_weight=mt.random.rand(1, 1))

# test binary classifier
new_y = (y_data > 0.5).astype(mt.int32)
Expand Down

0 comments on commit 576923b

Please sign in to comment.