Skip to content

Commit

Permalink
Add a helper function to create an empty placeholder context and upda…
Browse files Browse the repository at this point in the history
…te tests to use the helper.

PiperOrigin-RevId: 650300708
  • Loading branch information
tfx-copybara committed Jul 8, 2024
1 parent 4e71a35 commit a269ae4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 7 additions & 0 deletions tfx/dsl/compiler/placeholder_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ def resolve_placeholder_expression(
return result


def empty_placeholder_context() -> ResolutionContext:
"""Returns an empty placeholder context."""
return ResolutionContext(
exec_info=data_types.ExecutionInfo(),
)


class _Operation(enum.Enum):
"""Alias for Operation enum types in placeholder.proto."""

Expand Down
13 changes: 11 additions & 2 deletions tfx/dsl/compiler/placeholder_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,8 +1689,8 @@ def testMakeProtoOpResolvesProto(self):
placeholder_pb2.PlaceholderExpression(),
)
resolved_proto = placeholder_utils.resolve_placeholder_expression(
placeholder_expression, placeholder_utils.ResolutionContext(
exec_info=data_types.ExecutionInfo()))
placeholder_expression, placeholder_utils.empty_placeholder_context()
)
self.assertProtoEquals(
"""
splits: "train"
Expand Down Expand Up @@ -2360,6 +2360,15 @@ def testDebugPredicatePlaceholder(self):
re.sub(r"\s+", "", actual_debug_str),
re.sub(r"\s+", "", expected_debug_str_pretty))

def test_empty_placeholder_context(self):
context = placeholder_utils.empty_placeholder_context()
self.assertEqual(
context,
placeholder_utils.ResolutionContext(
exec_info=data_types.ExecutionInfo()
)
)


if __name__ == "__main__":
tf.test.main()
5 changes: 1 addition & 4 deletions tfx/dsl/placeholder/placeholder_test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from tfx.dsl.compiler import placeholder_utils
from tfx.dsl.placeholder import placeholder_base
from tfx.orchestration.portable import data_types


def resolve(
Expand All @@ -39,9 +38,7 @@ def resolve(
return placeholder_utils.resolve_placeholder_expression(
placeholder.encode(),
resolution_context
or placeholder_utils.ResolutionContext(
exec_info=data_types.ExecutionInfo()
),
or placeholder_utils.empty_placeholder_context(),
)


Expand Down

0 comments on commit a269ae4

Please sign in to comment.