Skip to content

ENH: DataFrame.sample should accept numpy.random.Generator #44486

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
gmaratos opened this issue Nov 16, 2021 · 2 comments
Closed

ENH: DataFrame.sample should accept numpy.random.Generator #44486

gmaratos opened this issue Nov 16, 2021 · 2 comments
Labels
Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Compat pandas objects compatability with Numpy or Python functions Enhancement

Comments

@gmaratos
Copy link

gmaratos commented Nov 16, 2021

This seems to be related to this issue and this merge. But currently DataFrame.sample does not allow Generator objects for random_state.

Rationale

As far as I can tell, the convention for numpy 1.21 random sampling, in their documentation is to create Generators using numpy.random.default_rng, so creating BitGenerators directly seems a little awkward.

Fix

This is a quick fix though because the generator has field to access the bit generator

from numpy.random import default_rng
rng = default_rng()
bit_generator = rng.bit_generator

@gmaratos gmaratos added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 16, 2021
@mzeitlin11
Copy link
Member

Thanks for the request @gmaratos! #42243 will be in 1.4, so support won't exist until then (except on pandas master if you'd like to check whether the changes will satisfy the request).

@mzeitlin11
Copy link
Member

Going to close for now then @gmaratos - please reopen if the 1.4 release doesn't satisfy what you're looking for

@mzeitlin11 mzeitlin11 added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Compat pandas objects compatability with Numpy or Python functions and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 19, 2021
@mzeitlin11 mzeitlin11 added this to the No action milestone Nov 19, 2021
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 Compat pandas objects compatability with Numpy or Python functions Enhancement
Projects
None yet
Development

No branches or pull requests

2 participants