@@ -137,6 +137,29 @@ def test_sample_inf_weights(self, obj):
137
137
with pytest .raises (ValueError , match = msg ):
138
138
obj .sample (n = 3 , weights = weights_with_ninf )
139
139
140
+ def test_sample_unit_probabilities_raises (self , obj ):
141
+ # GH#61516
142
+ high_variance_weights = [1 ] * 10
143
+ high_variance_weights [0 ] = 100
144
+ msg = (
145
+ "Invalid weights: If `replace`=False,"
146
+ " total unit probabilities have to be less than 1"
147
+ )
148
+ with pytest .raises (ValueError , match = msg ):
149
+ obj .sample (n = 2 , weights = high_variance_weights , replace = False )
150
+
151
+ # edge case, n*max(weights)/sum(weights) == 1
152
+ edge_variance_weights = [1 ] * 10
153
+ edge_variance_weights [0 ] = 9
154
+ # should not raise
155
+ obj .sample (n = 2 , weights = edge_variance_weights , replace = False )
156
+
157
+ low_variance_weights = [1 ] * 10
158
+ low_variance_weights [0 ] = 8
159
+ # should not raise
160
+ obj .sample (n = 2 , weights = low_variance_weights , replace = False )
161
+
162
+
140
163
def test_sample_zero_weights (self , obj ):
141
164
# All zeros raises errors
142
165
0 commit comments