Skip to content

Commit e5f9a07

Browse files
committed
implement the exception
1 parent 649a898 commit e5f9a07

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

pandas/core/sample.py

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

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

0 commit comments

Comments
 (0)