Skip to content

PERF: Series + range #51502

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

Closed
jbrockmendel opened this issue Feb 20, 2023 · 0 comments · Fixed by #51518
Closed

PERF: Series + range #51502

jbrockmendel opened this issue Feb 20, 2023 · 0 comments · Fixed by #51518
Labels
Needs Triage Issue that has not been reviewed by a pandas team member Performance Memory or execution speed performance

Comments

@jbrockmendel
Copy link
Member

jbrockmendel commented Feb 20, 2023

In [5]: ser = pd.Series(0, index=range(10_000_000))

In [6]: %timeit ser + range(len(ser))
737 ms ± 15.8 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

In [7]: %timeit ser + np.arange(len(ser))
34.5 ms ± 526 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

Somewhere along the line we do a sub-optimal conversion of the range to an ndarray. We can improve perf by using np.arange(obj) instead of np.asarray(obj).

Discovered while tracking down slow tests, in particular test_resample_equivalent_offsets takes a little more than 1% of the test suite runtime and most of that is in adding a range to a Series.

@jbrockmendel jbrockmendel added Performance Memory or execution speed performance Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Triage Issue that has not been reviewed by a pandas team member Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant