From d8ccc690d16b9e35d977448a5d13449927a68329 Mon Sep 17 00:00:00 2001 From: till-m <36440677+till-m@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:51:02 +0100 Subject: [PATCH] deprecation warning for sorted parameters (#532) * warn when registering array * bump version --- bayes_opt/target_space.py | 13 +++++++++++++ pyproject.toml | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bayes_opt/target_space.py b/bayes_opt/target_space.py index 7dddbd51..41833062 100644 --- a/bayes_opt/target_space.py +++ b/bayes_opt/target_space.py @@ -102,6 +102,8 @@ def __init__( else: self._constraint_values = np.empty(shape=(0, constraint.lb.size), dtype=float) + self._sorting_warning_already_shown = False # TODO: remove in future version + def __contains__(self, x: NDArray[Float]) -> bool: """Check if this parameter has already been registered. @@ -330,6 +332,17 @@ def register( >>> len(space) 1 """ + # TODO: remove in future version + if isinstance(params, np.ndarray) and not self._sorting_warning_already_shown: + msg = ( + "You're attempting to register an np.ndarray. Currently, the optimizer internally sorts" + " parameters by key and expects any registered array to respect this order. In future" + " versions this behaviour will change and the order as given by the pbounds dictionary" + " will be used. If you wish to retain sorted parameters, please manually sort your pbounds" + " dictionary before constructing the optimizer." + ) + warn(msg, stacklevel=1) + self._sorting_warning_already_shown = True x = self._as_array(params) if x in self: if self._allow_duplicate_points: diff --git a/pyproject.toml b/pyproject.toml index 44e31df0..7c39fc0d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "bayesian-optimization" -version = "2.0.0" +version = "2.0.1" description = "Bayesian Optimization package" authors = ["Fernando Nogueira"] license = "MIT"