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

PERF: avoid unnecessary copies factorize #46109

Merged
merged 1 commit into from
Feb 26, 2022

Conversation

jbrockmendel
Copy link
Member

Reached via yak-shaving on #33276.

The core.algorithms change should only affect non-64bit cases. The Categorical change could help across the board.

import numpy as np
import pandas as pd

arr = np.arange(10**5, dtype="uint32")

%timeit pd.factorize(arr)
2.27 ms ± 67.8 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)  # <- main
1.08 ms ± 28.1 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)  # <- PR

cat = pd.Categorical(np.arange(10**5))
%timeit cat.factorize()
2.67 ms ± 115 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)  # <- main
1.06 ms ± 37.4 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)  # <- PR

cat2 = pd.Categorical(["A", "B", "C"] * 1000)
%timeit cat2.factorize()
108 µs ± 11.3 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)  # <- main
30.9 µs ± 919 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)  # <- PR

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Might be good to follow up with a whatsnew note

@mroeschke mroeschke added this to the 1.5 milestone Feb 22, 2022
@mroeschke mroeschke added Performance Memory or execution speed performance Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff labels Feb 22, 2022
@jbrockmendel
Copy link
Member Author

Might be good to follow up with a whatsnew note

sure. will add that to the next "assorted" branch

@jreback jreback merged commit 150cf99 into pandas-dev:main Feb 26, 2022
@jbrockmendel jbrockmendel deleted the perf-values_for_rank branch February 26, 2022 20:19
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants