Skip to content

Commit

Permalink
[#167] Improve the "unknown distribution" error message
Browse files Browse the repository at this point in the history
  • Loading branch information
riley-harper committed Dec 2, 2024
1 parent 5d0ea0b commit 943fc0a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,9 @@ def _choose_randomized_parameters(
stdev = value["standard_deviation"]
parameter_choices[key] = rng.normalvariate(mean, stdev)
else:
raise ValueError("unknown distribution")
raise ValueError(
f"Unknown distribution '{distribution}'. Please choose one of 'randint', 'uniform', or 'normal'."
)
# All other types (including strings) are passed through unchanged.
else:
parameter_choices[key] = value
Expand Down
24 changes: 24 additions & 0 deletions hlink/tests/model_exploration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,30 @@ def test_get_model_parameters_search_strategy_randomized_uses_seed(training_conf
]


def test_get_model_parameters_search_strategy_randomized_unknown_distribution(
training_conf,
):
"""
Passing a distrbution other than "uniform", "randint", or "normal" is an error.
"""
training_conf["training"]["model_parameter_search"] = {
"strategy": "randomized",
"num_samples": 10,
}
training_conf["training"]["model_parameters"] = [
{
"type": "decision_tree",
"minInfoGain": {"distribution": "laplace", "location": 0.0, "scale": 1.0},
}
]

with pytest.raises(
ValueError,
match="Unknown distribution 'laplace'. Please choose one of 'randint', 'uniform', or 'normal'.",
):
_get_model_parameters(training_conf["training"])


# -------------------------------------
# Tests that probably should be moved
# -------------------------------------
Expand Down

0 comments on commit 943fc0a

Please sign in to comment.