@@ -253,6 +253,26 @@ def test_max_with_constraint_identical_target_value():
253253 assert space .max () == {"params" : {"p1" : 2 , "p2" : 3 }, "target" : 5 , "constraint" : - 1 }
254254
255255
256+ def test_max_categorical () -> None :
257+ PBOUNDS = {
258+ "first_float" : (0.0 , 1.0 ),
259+ "categorical_value" : ("a" , "b" , "c" , "d" ),
260+ "second_float" : (0.0 , 1.0 ),
261+ }
262+
263+ def _f (first_float : float , categorical_value : str , second_float : float ) -> float :
264+ return second_float if categorical_value == "c" else first_float
265+
266+ space = TargetSpace (_f , PBOUNDS )
267+ space .probe (params = {"first_float" : 0.1 , "categorical_value" : "a" , "second_float" : 0.1 })
268+ space .probe (params = {"first_float" : 0.1 , "categorical_value" : "b" , "second_float" : 0.9 })
269+ space .probe (params = {"first_float" : 0.1 , "categorical_value" : "c" , "second_float" : 0.8 })
270+ space .probe (params = {"first_float" : 0.1 , "categorical_value" : "d" , "second_float" : 0.9 })
271+
272+ expected = {"first_float" : 0.1 , "categorical_value" : "c" , "second_float" : 0.8 }
273+ assert space .max ()["params" ] == expected
274+
275+
256276def test_res ():
257277 PBOUNDS = {"p1" : (0 , 10 ), "p2" : (1 , 100 )}
258278 space = TargetSpace (target_func , PBOUNDS )
0 commit comments