Skip to content

Commit 46916db

Browse files
authored
DOC: document default behaviour of sample methods when random_state = None (#59073)
* Document the default None random_state of sample Previously the default random state of the Series/DataFrame/GroupBy `sample` methods was unclear as the documentation for the behaviour when `random_state=None` was hidden in the `pandas.core.common.random_state` helper function. This commit documents how `sample` will just defer to the random state of `numpy.random` when no `random_state` parameter is passed. * Add Series.sample to GroupBy See Also docstring * Format None type as code in doc strings
1 parent 39a3bf3 commit 46916db

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

pandas/core/generic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5731,7 +5731,7 @@ def sample(
57315731
replace : bool, default False
57325732
Allow or disallow sampling of the same row more than once.
57335733
weights : str or ndarray-like, optional
5734-
Default 'None' results in equal probability weighting.
5734+
Default ``None`` results in equal probability weighting.
57355735
If passed a Series, will align with target object on index. Index
57365736
values in weights not found in sampled object will be ignored and
57375737
index values in sampled object not in weights will be assigned
@@ -5746,6 +5746,7 @@ def sample(
57465746
random_state : int, array-like, BitGenerator, np.random.RandomState, np.random.Generator, optional
57475747
If int, array-like, or BitGenerator, seed for random number generator.
57485748
If np.random.RandomState or np.random.Generator, use as given.
5749+
Default ``None`` results in sampling with the current state of np.random.
57495750
57505751
.. versionchanged:: 1.4.0
57515752

pandas/core/groupby/groupby.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5389,6 +5389,7 @@ def sample(
53895389
random_state : int, array-like, BitGenerator, np.random.RandomState, np.random.Generator, optional
53905390
If int, array-like, or BitGenerator, seed for random number generator.
53915391
If np.random.RandomState or np.random.Generator, use as given.
5392+
Default ``None`` results in sampling with the current state of np.random.
53925393
53935394
.. versionchanged:: 1.4.0
53945395
@@ -5403,6 +5404,7 @@ def sample(
54035404
See Also
54045405
--------
54055406
DataFrame.sample: Generate random samples from a DataFrame object.
5407+
Series.sample: Generate random samples from a Series object.
54065408
numpy.random.choice: Generate a random sample from a given 1-D numpy
54075409
array.
54085410

0 commit comments

Comments
 (0)