Skip to content

Commit d34ec00

Browse files
committed
implement the exception
1 parent e3e0aaa commit d34ec00

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pandas/core/sample.py

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

153+
if weight_sum > 1 and replace:
154+
raise ValueError("Invalid weights: When `replace`=True weights must add up to less than 1")
155+
153156
return random_state.choice(obj_len, size=size, replace=replace, p=weights).astype(
154157
np.intp, copy=False
155158
)

0 commit comments

Comments
 (0)