Skip to content

Commit

Permalink
Added support for default values to Lightweight python components (#890)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark-kun authored and k8s-ci-robot committed Mar 1, 2019
1 parent f5bdf24 commit 5ab368a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions sdk/python/kfp/components/_python_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def annotation_to_type_struct(annotation):
input_spec = InputSpec(
name=parameter.name,
type=type_struct,
default=str(parameter.default) if parameter.default is not inspect.Parameter.empty else None,
)
inputs.append(input_spec)

Expand Down
12 changes: 12 additions & 0 deletions sdk/python/tests/components/test_python_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ def add_two_numbers_decorated(a: float, b: float) -> float:
self.assertEqual(component_spec.description.strip(), expected_description.strip())
self.assertEqual(component_spec.implementation.container.image, expected_image)

def test_saving_default_values(self):
from typing import NamedTuple
def add_multiply_two_numbers(a: float = 3, b: float = 5) -> NamedTuple('DummyName', [('sum', float), ('product', float)]):
'''Returns sum and product of two arguments'''
return (a + b, a * b)

func = add_multiply_two_numbers
component_spec = comp._python_op._func_to_component_spec(func)

self.assertEqual(component_spec.inputs[0].default, '3')
self.assertEqual(component_spec.inputs[1].default, '5')

def test_end_to_end_python_component_pipeline_compilation(self):
import kfp.components as comp

Expand Down

0 comments on commit 5ab368a

Please sign in to comment.