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

SDK - Added support for default values to Lightweight python components #890

Merged
Show file tree
Hide file tree
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
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