Skip to content

Commit 7fb2b79

Browse files
committed
Add syntactic sugar for copying NumericalHyperparameterSettings
1 parent d7629f3 commit 7fb2b79

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

dataikuapi/dss/ml.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ def set_explicit_values(self, values):
743743
- the definition mode of the current numerical hyperparameter to "EXPLICIT"
744744
745745
:param values: the explicit list of numerical values considered for this hyperparameter in the search
746-
:type values: list of float | int
746+
:type values: list of float | list of int
747747
"""
748748
self.values = values
749749
self.definition_mode = "EXPLICIT"
@@ -760,7 +760,7 @@ def values(self):
760760
def values(self, values):
761761
"""
762762
:param values: the explicit list of numerical values considered for this hyperparameter in the search
763-
:type values: list of float | int
763+
:type values: list of float | list of int
764764
"""
765765
error_message = "Invalid values input type for hyperparameter " \
766766
"\"{}\": ".format(self.name) + \
@@ -1064,12 +1064,19 @@ def __setattr__(self, attr_name, value):
10641064
target.set_values(value)
10651065
elif isinstance(target, NumericalHyperparameterSettings):
10661066
if isinstance(value, list):
1067-
target.set_explicit_values(values=value)
1067+
# algo.hyperparam = [x, y, z]
1068+
target.set_explicit_values(values=1)
10681069
elif isinstance(value, Range):
1070+
# algo.hyperparam = Range(min=x, max=y, nb_values=z)
10691071
target.set_range(min=value.min, max=value.max, nb_values=value.nb_values)
1072+
elif isinstance(value, NumericalHyperparameterSettings):
1073+
# algo.hyperparam = other_algo.other_hyperparam
1074+
target.set_range(min=value.range.min, max=value.range.max, nb_values=value.range.nb_values)
1075+
target.set_explicit_values(values=value.values.copy())
1076+
target.definition_mode = value.definition_mode
10701077
else:
10711078
raise TypeError(("Invalid type for NumericalHyperparameterSettings {}\n" +
1072-
"Expecting either a list or a Range").format(attr_name))
1079+
"Expecting either list, Range or NumericalHyperparameterSettings").format(attr_name))
10731080
else:
10741081
# simple parameter
10751082
assert isinstance(value, type(target)), "Invalid type {} for parameter {}: expected {}".format(type(value), attr_name, type(target))

0 commit comments

Comments
 (0)