Skip to content

Commit 4382def

Browse files
committed
implement the exception
1 parent e447dd4 commit 4382def

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pandas/core/sample.py

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

153+
if weight_sum > 1 and not replace:
154+
raise ValueError(
155+
"Invalid weights: If `replace`=False weights must sum to less than 1"
156+
)
157+
153158
return random_state.choice(obj_len, size=size, replace=replace, p=weights).astype(
154159
np.intp, copy=False
155160
)

0 commit comments

Comments
 (0)