コード例 #1
0
class Unnest(
    resolver_op.ResolverOp,
    arg_data_types=(resolver_op.DataTypes.ARTIFACT_MULTIMAP,),
    return_data_type=resolver_op.DataTypes.ARTIFACT_MULTIMAP_LIST,
):
  """Unnest operator.

  Unnest operator split a *`key` channel* of multiple artifacts into multiple
  dicts each with a channel with single artifact. Pseudo code example:

      Unnest({x: [x1, x2, x3]}, key=x)
        = [{x: [x1]}, {x: [x2]}, {x: [x3]}]

  For channels other than key channel remains the same. Pseudo code example:

      Unnest({x: [x1, x2, x3], y: [y1]}, key=x)
        = [{x: [x1], y: [y1]}, {x: [x2], y: [y1]}, {x: [x3], y: [y1]}]
  """
  key = resolver_op.ResolverOpProperty(type=str)

  def apply(self, input_dict: typing_utils.ArtifactMultiMap):
    if self.key not in input_dict:
      raise exceptions.FailedPreconditionError(
          f'Input dict does not contain the key {self.key}. '
          f'Available: {list(input_dict.keys())}')

    main_channel = input_dict.get(self.key)
    rest = {k: v for k, v in input_dict.items() if k != self.key}
    result = []
    for main_artifact in main_channel:
      result.append({self.key: [main_artifact], **rest})
    return result
コード例 #2
0
class RepeatOp(resolver_op.ResolverOp):
    num = resolver_op.ResolverOpProperty(type=int)

    def __init__(self):
        RepeatOp.last_created = self

    def apply(self, input_dict):
        return {key: value * self.num for key, value in input_dict.items()}
コード例 #3
0
ファイル: resolver_op_test.py プロジェクト: jay90099/tfx
 class BadProperty(resolver_op.ResolverOp):  # pylint: disable=unused-variable
     str_prop = resolver_op.ResolverOpProperty(type=str, default=42)
コード例 #4
0
ファイル: resolver_op_test.py プロジェクト: jay90099/tfx
class Repeat(resolver_op.ResolverOp,
             return_data_type=resolver_op.DataTypes.ARTIFACT_MULTIMAP_LIST):
    n = resolver_op.ResolverOpProperty(type=int)

    def apply(self, input_dict):
        return [copy.deepcopy(input_dict) for _ in range(self.n)]
コード例 #5
0
ファイル: resolver_op_test.py プロジェクト: jay90099/tfx
class Bar(resolver_op.ResolverOp):
    bar = resolver_op.ResolverOpProperty(type=str, default='bar')

    def apply(self, input_dict):
        return input_dict
コード例 #6
0
ファイル: resolver_op_test.py プロジェクト: jay90099/tfx
class Foo(resolver_op.ResolverOp):
    foo = resolver_op.ResolverOpProperty(type=int)

    def apply(self, input_dict):
        return input_dict
コード例 #7
0
ファイル: resolver_op_test.py プロジェクト: jay90099/tfx
        class CustomOp(resolver_op.ResolverOp):
            optional_mapping = resolver_op.ResolverOpProperty(
                type=Optional[Mapping[str, str]], default=None)

            def apply(self, input_dict):
                return input_dict
コード例 #8
0
class Bar(resolver_op.ResolverOp):
    """Dummy ResolverOperator Bar."""
    bar = resolver_op.ResolverOpProperty(type=str)

    def apply(self, input_dict):
        return input_dict
コード例 #9
0
class Foo(resolver_op.ResolverOp):
    """Dummy ResolverOperator Foo."""
    foo = resolver_op.ResolverOpProperty(type=int)

    def apply(self, input_dict):
        return input_dict