Skip to content

Commit a05beaa

Browse files
committed
implement the exception
1 parent b8371f5 commit a05beaa

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+
if weights is not None:
154+
is_max_weight_dominating = size * weights.max() > 1
155+
if is_max_weight_dominating and not replace:
156+
raise ValueError(
157+
"Invalid weights: If `replace`=False, "
158+
"total 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)