Skip to content

Commit

Permalink
deprecation warning for sorted parameters (#532)
Browse files Browse the repository at this point in the history
* warn when registering array

* bump version
  • Loading branch information
till-m authored Dec 9, 2024
1 parent 8cc0f0e commit d8ccc69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions bayes_opt/target_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit d8ccc69

Please sign in to comment.