File tree 2 files changed +20
-5
lines changed
Filter options
2 files changed +20
-5
lines changed
Original file line number Diff line number Diff line change @@ -202,11 +202,6 @@ def _choose_algorithm(self, algorithm, metric):
202
202
return algorithm
203
203
204
204
def _evaluate_hypercube_faces (self ):
205
- lower , upper = np .transpose (self .bounds )
206
- if np .any (upper <= lower ):
207
- raise ValueError (
208
- f"invalid bounds: upper ({ upper } ) is not larger than lower ({ lower } )"
209
- )
210
205
n_dims = len (self .bounds )
211
206
# Start the queue with all vertices, then recursively create all faces.
212
207
queue = set (itertools .product (* self .bounds ))
@@ -434,6 +429,11 @@ def _validate_data(
434
429
):
435
430
if self .bounds is not None :
436
431
lower , upper = np .transpose (self .bounds )
432
+ if np .any (upper <= lower ):
433
+ raise ValueError (
434
+ f"invalid bounds: upper ({ upper } ) is not larger than lower "
435
+ f"({ lower } )"
436
+ )
437
437
if np .any (X < lower ):
438
438
raise ValueError ("samples must be larger than lower bound" )
439
439
if np .any (X > upper ):
Original file line number Diff line number Diff line change @@ -274,6 +274,21 @@ def test_kde_hypercube_faces(n_dims, expected_counts):
274
274
np .testing .assert_array_equal (actual_counts , expected_counts )
275
275
276
276
277
+ def test_kde_with_bounds_invalid ():
278
+ with pytest .raises (ValueError , match = "invalid bounds" ):
279
+ KernelDensity (bounds = [(3 , 1 )]).fit (None )
280
+
281
+ kde = KernelDensity (bounds = [(0 , 2 )]).fit (np .ones ((3 , 1 )))
282
+ with pytest .raises (NotImplementedError ):
283
+ kde .sample ()
284
+
285
+ with pytest .raises (ValueError , match = "samples must be larger" ):
286
+ KernelDensity (bounds = [(1 , 2 )]).fit (np .zeros ((3 , 1 )))
287
+
288
+ with pytest .raises (ValueError , match = "samples must be smaller" ):
289
+ KernelDensity (bounds = [(1 , 2 )]).fit (3 * np .ones ((3 , 1 )))
290
+
291
+
277
292
def test_kde_bounded_density ():
278
293
n_samples , n_features = (100_000 , 2 )
279
294
rng = np .random .RandomState (0 )
You can’t perform that action at this time.
0 commit comments