Skip to content

Commit 01ec191

Browse files
authored
handle none for optional inputs (#84)
* 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]>
1 parent bb6f654 commit 01ec191

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

inference_schema/schema_decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def decorator_input(user_run, instance, args, kwargs):
5454
'is not in the decorated function.'.format(param_name))
5555
param_position = arg_names.index(param_name)
5656
args[param_position] = _deserialize_input_argument(args[param_position], param_type, param_name)
57-
elif param_name not in kwargs.keys() and optional:
57+
elif optional and (param_name not in kwargs.keys() or not kwargs[param_name]):
5858
pass
5959
else:
6060
kwargs[param_name] = _deserialize_input_argument(kwargs[param_name], param_type, param_name)

tests/test_pandas_parameter_type.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,21 @@ def test_pandas_params_handling_without_params(self, decorated_pandas_func_param
110110
assert result[0][0] == "this is a string starting with"
111111
assert result[1] == 0
112112

113+
def test_pandas_params_handling_with_none_params(self, decorated_pandas_func_parameters):
114+
pandas_input_data = {
115+
"columns": [
116+
"sentence1"
117+
],
118+
"data": [
119+
["this is a string starting with"]
120+
],
121+
"index": [0]
122+
}
123+
parameters = None
124+
result = decorated_pandas_func_parameters(pandas_input_data, params=parameters)
125+
assert result[0][0] == "this is a string starting with"
126+
assert result[1] == 0
127+
113128

114129
class TestNestedType(object):
115130

0 commit comments

Comments
 (0)