Skip to content

Commit 1dfc85d

Browse files
committed
update documentation
1 parent 23926f6 commit 1dfc85d

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

doc/source/user_guide/indexing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ to have different probabilities, you can pass the ``sample`` function sampling w
700700
701701
s = pd.Series([0, 1, 2, 3, 4, 5])
702702
example_weights = [0, 0, 0.2, 0.2, 0.2, 0.4]
703-
s.sample(n=3, weights=example_weights)
703+
s.sample(n=2, weights=example_weights)
704704
705705
# Weights will be re-normalized automatically
706706
example_weights2 = [0.5, 0, 0, 0, 0, 0]
@@ -714,7 +714,7 @@ as a string.
714714
715715
df2 = pd.DataFrame({'col1': [9, 8, 7, 6],
716716
'weight_column': [0.5, 0.4, 0.1, 0]})
717-
df2.sample(n=3, weights='weight_column')
717+
df2.sample(n=2, weights='weight_column')
718718
719719
``sample`` also allows users to sample columns instead of rows using the ``axis`` argument.
720720

doc/source/whatsnew/v0.16.1.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ facilitate replication. (:issue:`2419`)
196196
197197
# weights are accepted.
198198
example_weights = [0, 0, 0.2, 0.2, 0.2, 0.4]
199-
example_series.sample(n=3, weights=example_weights)
199+
example_series.sample(n=2, weights=example_weights)
200200
201201
# weights will also be normalized if they do not sum to one,
202202
# and missing values will be treated as zeros.
@@ -209,8 +209,8 @@ when sampling from rows.
209209

210210
.. ipython:: python
211211
212-
df = pd.DataFrame({"col1": [9, 8, 7, 6], "weight_column": [0.5, 0.4, 0.1, 0]})
213-
df.sample(n=3, weights="weight_column")
212+
df = pd.DataFrame({"col1": [9, 8, 7, 6], "weight_column": [0.5, 0.4, 0.1, 0]})
213+
df.sample(n=2, weights="weight_column")
214214
215215
216216
.. _whatsnew_0161.enhancements.string:

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ Other
890890
- Bug in :meth:`DataFrame.query` where using duplicate column names led to a ``TypeError``. (:issue:`59950`)
891891
- Bug in :meth:`DataFrame.query` which raised an exception or produced incorrect results when expressions contained backtick-quoted column names containing the hash character ``#``, backticks, or characters that fall outside the ASCII range (U+0001..U+007F). (:issue:`59285`) (:issue:`49633`)
892892
- Bug in :meth:`DataFrame.query` which raised an exception when querying integer column names using backticks. (:issue:`60494`)
893+
- Bug in :meth:`DataFrame.sample` with ``replace=False`` and ``(n * max(weights) / sum(weights)) > 1``, the method would return biased results. Now raises ``ValueError``. (:issue:`61516`)
893894
- Bug in :meth:`DataFrame.shift` where passing a ``freq`` on a DataFrame with no columns did not shift the index correctly. (:issue:`60102`)
894895
- Bug in :meth:`DataFrame.sort_index` when passing ``axis="columns"`` and ``ignore_index=True`` and ``ascending=False`` not returning a :class:`RangeIndex` columns (:issue:`57293`)
895896
- Bug in :meth:`DataFrame.sort_values` where sorting by a column explicitly named ``None`` raised a ``KeyError`` instead of sorting by the column as expected. (:issue:`61512`)

pandas/core/generic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5815,6 +5815,8 @@ def sample(
58155815
If weights do not sum to 1, they will be normalized to sum to 1.
58165816
Missing values in the weights column will be treated as zero.
58175817
Infinite values not allowed.
5818+
When replace = False will not allow ``(n * max(weights) / sum(weights)) > 1``,
5819+
in order to avoid biased results.
58185820
random_state : int, array-like, BitGenerator, np.random.RandomState, np.random.Generator, optional
58195821
If int, array-like, or BitGenerator, seed for random number generator.
58205822
If np.random.RandomState or np.random.Generator, use as given.

0 commit comments

Comments
 (0)