Skip to content

Commit 88a0bc3

Browse files
committed
implement the exception
1 parent 8987a08 commit 88a0bc3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/core/sample.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ def sample(
150150
else:
151151
raise ValueError("Invalid weights: weights sum to zero")
152152

153+
is_max_weight_dominating = size * max(weights) > 1
154+
if (is_max_weight_dominating and not replace):
155+
raise ValueError(
156+
"Invalid weights: If `replace`=False,"
157+
" total unit probabilities have to be less than 1"
158+
)
159+
153160
return random_state.choice(obj_len, size=size, replace=replace, p=weights).astype(
154161
np.intp, copy=False
155162
)

0 commit comments

Comments
 (0)