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/ENH: allow Generator in sampling methods #42243

Merged
merged 7 commits into from Jul 4, 2021

Conversation

mzeitlin11
Copy link
Member

The perf gap is pretty crazy:


In [10]: rng = np.random.default_rng()

In [11]: ser = pd.Series(np.zeros(10 ** 6))

In [12]: %timeit ser.sample(n=10 ** 4)
13.8 ms ± 231 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [13]: %timeit ser.sample(n=10 ** 4, random_state=rng)
569 µs ± 8.11 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

Leaving #28440 open because I think the end goal should still be to make using these the default. But assuming that change isn't too easy since will be a breaking change?

@mzeitlin11 mzeitlin11 added Enhancement Performance Memory or execution speed performance labels Jun 25, 2021
Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

looks fine a question.

np.random.RandomState,
]
else:
RandomState = Union[int, ArrayLike, np.random.Generator, np.random.RandomState]
Copy link
Contributor

Choose a reason for hiding this comment

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

umm why is BitGenerator not in the 2nd part?

Copy link
Member Author

Choose a reason for hiding this comment

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

BitGenerator isn't exposed until numpy >= 1.18. Have added a comment about this and removed the else clause (since that would mean we're not type checking anyway so the definition doesn't matter)

@jreback jreback added this to the 1.4 milestone Jul 2, 2021
@jreback jreback merged commit 9a6ce3c into pandas-dev:master Jul 4, 2021
@jreback
Copy link
Contributor

jreback commented Jul 4, 2021

thanks @mzeitlin11

might need to slightly revist after we drop 1.17 (shortly)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: random_state should permit numpy.random.Generator
2 participants