Skip to content

REGR: perf regression in Series.combine_first #57034

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 4 commits into from
Jan 25, 2024

Conversation

lukemanley
Copy link
Member

import pandas as pd
import numpy as np

N = 1_000_000


# different indexes
s1 = pd.Series(np.random.randn(N))
s1 = s1[::2].sample(frac=1.0)
s2 = pd.Series(np.random.randn(N))
%timeit s1.combine_first(s2)

# 523 ms ± 7.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)   <- main
# 227 ms ± 4.33 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)  <- PR


# same index
s1 = pd.Series(np.random.randn(N))
s1[::2] = np.nan
s2 = pd.Series(np.random.randn(N))
%timeit s1.combine_first(s2)

# 282 ms ± 5.64 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)   <- main
# 7 ms ± 64.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)  <- PR

@lukemanley lukemanley added Performance Memory or execution speed performance Regression Functionality that used to work in a prior pandas version labels Jan 23, 2024
@lukemanley lukemanley added this to the 2.2.1 milestone Jan 23, 2024
@@ -87,6 +87,7 @@
from pandas.core.dtypes.dtypes import (
CategoricalDtype,
ExtensionDtype,
SparseDtype,
Copy link
Member

Choose a reason for hiding this comment

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

Surprising to see this here. Maybe more motivation for #56518

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, a bit unfortunate. Alternatively, the sparse issue was previously xfailed and could be xfailed again in order to avoid this:

https://github.com/pandas-dev/pandas/pull/51777/files#diff-16458c6ca46c7c2e895b1fad1300009d8285d19cdbef3023a33f520d15bc7085L333

@mroeschke mroeschke merged commit d928a5c into pandas-dev:main Jan 25, 2024
@mroeschke
Copy link
Member

Thanks @lukemanley

meeseeksmachine pushed a commit to meeseeksmachine/pandas that referenced this pull request Jan 25, 2024
mroeschke pushed a commit that referenced this pull request Jan 25, 2024
…ombine_first) (#57072)

Backport PR #57034: REGR: perf regression in Series.combine_first

Co-authored-by: Luke Manley <[email protected]>
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
* fix perf regression in Series.combine_first

* fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance Memory or execution speed performance Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: combine_first major performance regression
3 participants