Skip to content

Commit 80dbe40

Browse files
committed
warn when registering array
1 parent 8cc0f0e commit 80dbe40

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

bayes_opt/target_space.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ def __init__(
102102
else:
103103
self._constraint_values = np.empty(shape=(0, constraint.lb.size), dtype=float)
104104

105+
self._sorting_warning_already_shown = False # TODO: remove in future version
106+
105107
def __contains__(self, x: NDArray[Float]) -> bool:
106108
"""Check if this parameter has already been registered.
107109
@@ -330,6 +332,17 @@ def register(
330332
>>> len(space)
331333
1
332334
"""
335+
# TODO: remove in future version
336+
if isinstance(params, np.ndarray) and not self._sorting_warning_already_shown:
337+
msg = (
338+
"You're attempting to register an np.ndarray. Currently, the optimizer internally sorts"
339+
" parameters by key and expects any registered array to respect this order. In future"
340+
" versions this behaviour will change and the order as given by the pbounds dictionary"
341+
" will be used. If you wish to retain sorted parameters, please manually sort your pbounds"
342+
" dictionary before constructing the optimizer."
343+
)
344+
warn(msg, stacklevel=1)
345+
self._sorting_warning_already_shown = True
333346
x = self._as_array(params)
334347
if x in self:
335348
if self._allow_duplicate_points:

0 commit comments

Comments
 (0)