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

FIX-#6632: Return Series instead of Dataframe for groupby.apply in case of experimental groupby #6649

Merged
merged 2 commits into from
Oct 21, 2023

Conversation

Garra1980
Copy link
Collaborator

What do these changes do?

  • 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 BUG: groupby and apply function produced unexpected column name __reduced__ #6632
  • tests added and passing
  • module layout described at docs/development/architecture.rst is up-to-date

@Garra1980 Garra1980 marked this pull request as ready for review October 15, 2023 14:28
@Garra1980 Garra1980 requested a review from a team as a code owner October 15, 2023 14:28
anmyachev
anmyachev previously approved these changes Oct 16, 2023
Copy link
Collaborator

@anmyachev anmyachev left a comment

Choose a reason for hiding this comment

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

LGTM!

@anmyachev
Copy link
Collaborator

@dchigarev any comments?

@dchigarev
Copy link
Collaborator

@dchigarev any comments?

Well, the only thing to notice is that it now always triggers the computation after groupby (because of the .columns access).

Previously we had a trend of getting rid of such explicit materialization, and now we're adding them back again. The changes are introduced to the general groupby method ._wrap_aggregation(), meaning that all the aggregations will be affected by the changes, not only .apply() calls for which we have to infer a new return type.

If we decide to keep the fix, maybe we should at least move it to the .apply() method, so the other methods won't be affected?

image

script to measure
import modin.pandas as pd
from asv_bench.benchmarks.utils.common import execute
import modin.config as cfg
import numpy as np
from timeit import default_timer as timer

# initialize workers
pd.DataFrame([cfg.NPartitions.get() * cfg.MinPartitionSize.get()]).to_numpy()

df = pd.DataFrame({"by_col": np.tile(np.arange(10_000), 100), "a": np.arange(1_000_000), "b": np.arange(1_000_000), "c": np.arange(1_000_000)})
execute(df) # trigger import

results = []

t1 = timer()
for _ in range(10):
    results.append(df.groupby("by_col").sum())
[execute(df) for df in results]
print(timer() - t1)

t1 = timer()
res = df.groupby("by_col").sum()
print(timer() - t1)

@anmyachev
Copy link
Collaborator

@dchigarev any comments?

Well, the only thing to notice is that it now always triggers the computation after groupby (because of the .columns access).

Previously we had a trend of getting rid of such explicit materialization, and now we're adding them back again. The changes are introduced to the general groupby method ._wrap_aggregation(), meaning that all the aggregations will be affected by the changes, not only .apply() calls for which we have to infer a new return type.

If we decide to keep the fix, maybe we should at least move it to the .apply() method, so the other methods won't be affected?

image

script to measure

import modin.pandas as pd
from asv_bench.benchmarks.utils.common import execute
import modin.config as cfg
import numpy as np
from timeit import default_timer as timer

# initialize workers
pd.DataFrame([cfg.NPartitions.get() * cfg.MinPartitionSize.get()]).to_numpy()

df = pd.DataFrame({"by_col": np.tile(np.arange(10_000), 100), "a": np.arange(1_000_000), "b": np.arange(1_000_000), "c": np.arange(1_000_000)})
execute(df) # trigger import

results = []

t1 = timer()
for _ in range(10):
    results.append(df.groupby("by_col").sum())
[execute(df) for df in results]
print(timer() - t1)

t1 = timer()
res = df.groupby("by_col").sum()
print(timer() - t1)

@dchigarev Good catch!

I was surprised that even df.groupby("by_col").sum() does not calculate the columns in advance. It doesn't look that difficult.

If we decide to keep the fix, maybe we should at least move it to the .apply() method, so the other methods won't be affected?

At least yes, you are right.

@anmyachev anmyachev self-requested a review October 17, 2023 13:53
@anmyachev anmyachev dismissed their stale review October 17, 2023 13:55

Missed materialization

@Garra1980
Copy link
Collaborator Author

If we decide to keep the fix, maybe we should at least move it to the .apply() method, so the other methods won't be affected?

you mean here - https://github.com/modin-project/modin/blob/master/modin/pandas/groupby.py#L657?

@dchigarev
Copy link
Collaborator

Signed-off-by: izamyati <igor.zamyatin@intel.com>
@Garra1980
Copy link
Collaborator Author

you mean here - https://github.com/modin-project/modin/blob/master/modin/pandas/groupby.py#L657?

yes

Okay, pls look at another attempt

dchigarev
dchigarev previously approved these changes Oct 20, 2023
modin/pandas/groupby.py Outdated Show resolved Hide resolved
Co-authored-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
@anmyachev anmyachev merged commit d142c84 into modin-project:master Oct 21, 2023
38 checks passed
anmyachev pushed a commit to anmyachev/modin that referenced this pull request Oct 30, 2023
…y.apply in case of experimental groupby (modin-project#6649)

Signed-off-by: izamyati <igor.zamyatin@intel.com>
Co-authored-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
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.

BUG: groupby and apply function produced unexpected column name __reduced__
3 participants