From 8fe2366fa9d3a88b2b934736c67d5efc40e5a9b0 Mon Sep 17 00:00:00 2001 From: Daniel <63580393+danrgll@users.noreply.github.com> Date: Fri, 12 Apr 2024 01:11:10 +0200 Subject: [PATCH] add valid type check for choices in categorical parameter --- neps/search_spaces/hyperparameters/categorical.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/neps/search_spaces/hyperparameters/categorical.py b/neps/search_spaces/hyperparameters/categorical.py index 9fa75253..af1cab76 100644 --- a/neps/search_spaces/hyperparameters/categorical.py +++ b/neps/search_spaces/hyperparameters/categorical.py @@ -39,6 +39,12 @@ def __init__( ) self.value: None | float | int | str = None + # Check if choices have valid types (float | int | str) + for choice in self.choices: + if not isinstance(choice, (float, int, str)): + raise TypeError( + f'Choice "{choice}" is not of a valid type (float, int, str)') + # Check if 'default' is in 'choices' if default is not None and default not in self.choices: raise ValueError(