Skip to content

PERF: replace with list, closes #28084 #28099

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 17 commits into from
Aug 26, 2019

Conversation

jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented Aug 22, 2019

based on the OP's example:

In [2]: df = pd.DataFrame({"A": 0, "B": 0}, index=range(4*10**7))

In [3]: %timeit df.replace([np.inf, -np.inf], np.nan)
5.18 s ± 423 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)    # <-- master
414 ms ± 7.19 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)   # <-- PR

In [4]: %timeit df.replace([np.inf, -np.inf], np.nan, inplace=True)
2.89 s ± 111 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)      # <-- master
69.6 µs ± 4 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)  # <-- PR

In [5]: %timeit df.replace([np.inf, -np.inf, 1], np.nan)
4.88 s ± 228 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)   # <-- master
466 ms ± 11.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)  # <-- PR

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

Probably worth adding an ASV.

@jbrockmendel
Copy link
Member Author

good idea, will do

@jbrockmendel
Copy link
Member Author

@WillAyd suggestions for how to make asv happy?

@TomAugspurger TomAugspurger added this to the 1.0 milestone Aug 26, 2019
@TomAugspurger TomAugspurger added the Performance Memory or execution speed performance label Aug 26, 2019
@TomAugspurger TomAugspurger merged commit 87d26ba into pandas-dev:master Aug 26, 2019
@TomAugspurger
Copy link
Contributor

Thanks!

@TomAugspurger
Copy link
Contributor

Whoops, just noticed this needs a release note: #28154

@jbrockmendel jbrockmendel deleted the replace_perf branch August 26, 2019 20:35
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pandas slow replace with int64 columns in dataframe
3 participants