Skip to content

Commit

Permalink
Extend the str feature of FunctionNode
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykubica committed Jul 17, 2024
1 parent df3e2a5 commit 2e1ea69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/tdastro/base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ def __init__(self, func, node_identifier=None, graph_base_seed=None, **kwargs):

def __str__(self):
"""Return the string representation of the function."""
return f"FunctionNode({self.func.__name__})"
# Extend the FunctionNode's string to include the name of the
# function it calls so we can wrap a variety of raw functions.
super_name = super().__str__()
return f"{super_name}:{self.func.__name__}"

def compute(self, **kwargs):
"""Execute the wrapped function.
Expand Down
2 changes: 2 additions & 0 deletions tests/tdastro/test_base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ def test_function_node_basic():
assert my_func.compute(value2=3.0, unused_param=5.0) == 4.0
assert my_func.compute(value2=3.0, value1=1.0) == 4.0

assert str(my_func) == "tdastro.base_models.FunctionNode:_test_func"


def test_function_node_chain():
"""Test that we can create and query a chained FunctionNode."""
Expand Down

0 comments on commit 2e1ea69

Please sign in to comment.