Skip to content

PERF: Don't sort labels in groupby.ffill/bfill #56902

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

Merged
merged 3 commits into from
Jan 16, 2024

Conversation

rhshadrach
Copy link
Member

@rhshadrach rhshadrach commented Jan 16, 2024

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.
N = 1000000
df = DataFrame(
    {"group": [1] * N + [2] * N, "value": [np.nan, 1.0] * N}
).set_index("group")
df = df.sample(N)

%timeit df.groupby("group").ffill()
gb = df.groupby("group")
gb.ffill()
%timeit gb.ffill()

# main
21.8 ms ± 676 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
17.5 ms ± 145 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

# PR
10.3 ms ± 159 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
5.56 ms ± 74.6 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

@rhshadrach rhshadrach added Groupby Performance Memory or execution speed performance Transformations e.g. cumsum, diff, rank labels Jan 16, 2024
@rhshadrach rhshadrach added this to the 3.0 milestone Jan 16, 2024
@rhshadrach rhshadrach requested a review from WillAyd as a code owner January 16, 2024 01:18
@mroeschke mroeschke merged commit 84aca21 into pandas-dev:main Jan 16, 2024
@mroeschke
Copy link
Member

Thanks @rhshadrach

@rhshadrach rhshadrach deleted the perf_gb_ffill branch January 16, 2024 21:37
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
* PERF: Don't sort labels in groupby.ffill/bfill

* PR#

* fixup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Performance Memory or execution speed performance Transformations e.g. cumsum, diff, rank
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants