Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT-#7254: Support right merge/join #7226

Merged
merged 22 commits into from May 13, 2024

Conversation

anmyachev
Copy link
Collaborator

@anmyachev anmyachev commented Apr 26, 2024

What do these changes do?

Blocked on #7251

Performance: 1.7 sec (the PR) vs 3.1 sec (on main) on Ray (8 cores)

import modin.pandas as pd
from time import time
import numpy as np
from modin.utils import execute

np.random.seed(42)

df1 = pd.DataFrame(np.random.randint(0, 100_000,size=(400_000, 64)))
df2 = pd.DataFrame(np.random.randint(0, 100_000,size=(400_000, 64)))
execute(df1)
execute(df2)


for _ in range(3):
    start = time()
    result = pd.merge(df1, df2, how="right", on=1)
    execute(result)
    print(f"{result.shape=}")
    print(f"merge time: {time()-start}")
  • first commit message and PR title follow format outlined here

    NOTE: If you edit the PR title to match this format, you need to add another commit (even if it's empty) or amend your last commit for the CI job that checks the PR title to pick up the new PR title.

  • passes flake8 modin/ asv_bench/benchmarks scripts/doc_checker.py
  • passes black --check modin/ asv_bench/benchmarks scripts/doc_checker.py
  • signed commit with git commit -s
  • Resolves Support right merge/join #7254
  • tests added and passing
  • module layout described at docs/development/architecture.rst is up-to-date

Signed-off-by: Anatoly Myachev <[email protected]>
Signed-off-by: Anatoly Myachev <[email protected]>
Signed-off-by: Anatoly Myachev <[email protected]>
Signed-off-by: Anatoly Myachev <[email protected]>
Signed-off-by: Anatoly Myachev <[email protected]>
…al reset_index for left merge"

Signed-off-by: Anatoly Myachev <[email protected]>
Signed-off-by: Anatoly Myachev <[email protected]>
Signed-off-by: Anatoly Myachev <[email protected]>
Signed-off-by: Anatoly Myachev <[email protected]>
Signed-off-by: Anatoly Myachev <[email protected]>
Signed-off-by: Anatoly Myachev <[email protected]>
Signed-off-by: Anatoly Myachev <[email protected]>
@anmyachev anmyachev changed the title PERF-#0000: try merge optimization FEAT-#7254: Support right merge/join May 13, 2024
@anmyachev anmyachev marked this pull request as ready for review May 13, 2024 00:33
@anmyachev anmyachev requested review from mvashishtha, RehanSD and a team as code owners May 13, 2024 00:33
Signed-off-by: Anatoly Myachev <[email protected]>
AndreyPavlenko
AndreyPavlenko previously approved these changes May 13, 2024
@anmyachev
Copy link
Collaborator Author

@YarShev ready for review

modin/tests/pandas/dataframe/test_join_sort.py Outdated Show resolved Hide resolved
modin/tests/pandas/dataframe/test_join_sort.py Outdated Show resolved Hide resolved
@@ -140,7 +141,11 @@ def test_join(test_data, test_data2):
lsuffix="_caller",
rsuffix="_other",
)
df_equals(modin_result, pandas_result)
if sorts[j]:
# sorting in `join` is implemented through range partitioning technique
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand this comment. sorting is just called in df_equals_and_sort. Should we remove this comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expanded the comment a little

def map_func(left, right, kwargs=kwargs): # pragma: no cover
return pandas.DataFrame.join(left, right, **kwargs)
if how in ["left", "inner"] or (
how == "right" and right._modin_frame._partitions.size != 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if left has size equals to 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty dataframes are processed at a higher level (simply defaulted to pandas) and all implementation logic relies on the fact that the left operand has a non-empty set of partitions. Therefore, to avoid an error, we need to handle this situation as before.

if (
(
how in ["left", "inner"]
or (how == "right" and right._modin_frame._partitions.size != 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: Anatoly Myachev <[email protected]>
Signed-off-by: Anatoly Myachev <[email protected]>
modin/tests/pandas/dataframe/test_join_sort.py Outdated Show resolved Hide resolved
data = np.random.randint(0, 100, size=(64, 64))
eval_general(
*create_test_dfs(data),
lambda df: df.join(df.iloc[:0], on=1, how=how, lsuffix="_caller"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we not use on parameter for a similar test with merge?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different threads of execution, for merge function we can omit this parameter so that a certain part of the code starts executing.

Co-authored-by: Iaroslav Igoshev <[email protected]>
@anmyachev anmyachev merged commit 1c0d9a6 into modin-project:main May 13, 2024
38 checks passed
@anmyachev anmyachev deleted the merge-swap-operand branch May 13, 2024 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support right merge/join
3 participants