Skip to content

Commit

Permalink
handle none for optional inputs (#84)
Browse files Browse the repository at this point in the history
* adjust to new params format with optional param in decorator

Signed-off-by: Walter Martin <[email protected]>

* handle None value for an optional parameter

Signed-off-by: Walter Martin <[email protected]>

* switch 'is None' to 'not' to cover more cases

Signed-off-by: Walter Martin <[email protected]>

* simplify condition

Signed-off-by: Walter Martin <[email protected]>

---------

Signed-off-by: Walter Martin <[email protected]>
  • Loading branch information
wamartin-aml authored Dec 29, 2023
1 parent bb6f654 commit 01ec191
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inference_schema/schema_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def decorator_input(user_run, instance, args, kwargs):
'is not in the decorated function.'.format(param_name))
param_position = arg_names.index(param_name)
args[param_position] = _deserialize_input_argument(args[param_position], param_type, param_name)
elif param_name not in kwargs.keys() and optional:
elif optional and (param_name not in kwargs.keys() or not kwargs[param_name]):
pass
else:
kwargs[param_name] = _deserialize_input_argument(kwargs[param_name], param_type, param_name)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_pandas_parameter_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ def test_pandas_params_handling_without_params(self, decorated_pandas_func_param
assert result[0][0] == "this is a string starting with"
assert result[1] == 0

def test_pandas_params_handling_with_none_params(self, decorated_pandas_func_parameters):
pandas_input_data = {
"columns": [
"sentence1"
],
"data": [
["this is a string starting with"]
],
"index": [0]
}
parameters = None
result = decorated_pandas_func_parameters(pandas_input_data, params=parameters)
assert result[0][0] == "this is a string starting with"
assert result[1] == 0


class TestNestedType(object):

Expand Down

0 comments on commit 01ec191

Please sign in to comment.