Example #1
0
    def create_task_from_component_and_arguments(pythonic_arguments):
        #Converting the argument names and not passing None arguments
        valid_argument_types = (
            str, int, float, bool, GraphInputArgument, TaskOutputArgument,
            PipelineParam
        )  #Hack for passed PipelineParams. TODO: Remove the hack once they're no longer passed here.
        arguments = {
            pythonic_name_to_input_name[k]:
            (v if isinstance(v, valid_argument_types) else str(v))
            for k, v in pythonic_arguments.items() if not isinstance(
                v, _DefaultValue
            )  # Skipping passing arguments for optional values that have not been overridden.
        }
        for key in arguments:
            if isinstance(arguments[key], PipelineParam):
                if kfp.TYPE_CHECK:
                    for input_spec in component_spec.inputs:
                        if input_spec.name == key:
                            if arguments[
                                    key].param_type is not None and not check_types(
                                        arguments[key].param_type.
                                        to_dict_or_str(), '' if input_spec.type
                                        is None else input_spec.type):
                                raise InconsistentTypeException(
                                    'Component "' + name + '" is expecting ' +
                                    key + ' to be type(' +
                                    str(input_spec.type) +
                                    '), but the passed argument is type(' +
                                    arguments[key].param_type.serialize() +
                                    ')')
                arguments[key] = str(arguments[key])

        task = TaskSpec(
            component_ref=component_ref,
            arguments=arguments,
        )
        if _created_task_transformation_handler:
            task = _created_task_transformation_handler[-1](task)
        return task
Example #2
0
    def test_check_types(self):
        #Core types
        typeA = {'ArtifactA': {'path_type': 'file', 'file_type': 'csv'}}
        typeB = {'ArtifactA': {'path_type': 'file', 'file_type': 'csv'}}
        self.assertTrue(check_types(typeA, typeB))
        typeC = {'ArtifactA': {'path_type': 'file', 'file_type': 'tsv'}}
        self.assertFalse(check_types(typeA, typeC))

        # Custom types
        typeA = {'A': {'X': 'value1', 'Y': 'value2'}}
        typeB = {'B': {'X': 'value1', 'Y': 'value2'}}
        typeC = {'A': {'X': 'value1'}}
        typeD = {'A': {'X': 'value1', 'Y': 'value3'}}
        self.assertFalse(check_types(typeA, typeB))
        self.assertFalse(check_types(typeA, typeC))
        self.assertTrue(check_types(typeC, typeA))
        self.assertFalse(check_types(typeA, typeD))