Skip to content

Commit

Permalink
fixes error with types
Browse files Browse the repository at this point in the history
  • Loading branch information
KaylaSeeley committed Nov 10, 2024
1 parent 34d3bb7 commit 155ce29
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion metaflow/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def __call__(self, deploy_time=False):
return self._check_type(val, deploy_time)

def _check_type(self, val, deploy_time):

# it is easy to introduce a deploy-time function that accidentally
# returns a value whose type is not compatible with what is defined
# in Parameter. Let's catch those mistakes early here, instead of
Expand All @@ -166,7 +167,12 @@ def _check_type(self, val, deploy_time):
% (self.parameter_name, self.field)
)

if self.parameter_type in TYPES:
if isinstance(self.parameter_type, list):
if not any(isinstance(val, x) for x in self.parameter_type):
msg += "Expected a %s." % TYPES[self.parameter_type]
raise ParameterFieldTypeMismatch(msg)
return str(val) if self.return_str else val
elif self.parameter_type in TYPES:
if type(val) != self.parameter_type:
msg += "Expected a %s." % TYPES[self.parameter_type]
raise ParameterFieldTypeMismatch(msg)
Expand Down
4 changes: 4 additions & 0 deletions metaflow/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,16 @@ def to_pod(value):
Value to convert to POD format. The value can be a string, number, list,
dictionary, or a nested structure of these types.
"""
from metaflow.parameters import DeployTimeField, deploy_time_eval

if isinstance(value, (str, int, float)):
return value
if isinstance(value, dict):
return {to_pod(k): to_pod(v) for k, v in value.items()}
if isinstance(value, (list, set, tuple)):
return [to_pod(v) for v in value]
if isinstance(value, DeployTimeField):
return to_pod(deploy_time_eval(value))
return str(value)


Expand Down

0 comments on commit 155ce29

Please sign in to comment.