Skip to content

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

Closed
@gmaratos

Description

@gmaratos

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffCompatpandas objects compatability with Numpy or Python functionsEnhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions