Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list type to parameters #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions model_metadata/model_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ def parameter_from_dict(d):
return FileParameter(value, **kwds)
elif dtype in ("bool", "boolean"):
return BooleanParameter(value, **kwds)
elif dtype in ("list",):
return ListParameter(value, **kwds)
else:
raise ValueError("{dtype}: unknown parameter type".format(dtype=dtype))

Expand Down Expand Up @@ -266,6 +268,23 @@ def value(self):
return self._value


class ListParameter(ModelParameterMixIn):

_dtype = "list"

def __init__(self, value, **kwds):
self._value = list(value)
self._desc = kwds.get("desc", None)

@property
def desc(self):
return self._desc

@property
def value(self):
return self._value


class NumberParameter(StringParameter, ModelParameterMixIn):

_kwds = ("units", "range")
Expand Down Expand Up @@ -425,6 +444,8 @@ def dtype_str(self):
return "float"
elif self.dtype is str:
return "str"
elif self.dtype is list:
return "list"
else:
return self.dtype

Expand Down Expand Up @@ -459,6 +480,8 @@ def norm(param):
dtype = float
elif dtype in ("str", "string", "file", "choice"):
dtype = str
elif dtype in ("list",):
dtype = list

if isinstance(range, dict):
range = (range["min"], range["max"])
Expand Down