Slackbot
07/13/2023, 1:22 PMElijah Ben Izzy
07/13/2023, 1:34 PMdriver.list_available_variables()
(https://hamilton.dagworks.io/en/latest/reference/drivers/Driver/#hamilton.driver.Driver.list_available_variables). This + tags enables you to list your varaibles then query specifically for them/organize them in the way you want.
That said, I’m not entirely sure what you mean by nodes that “aren’t all executable”. Do you have some psuedocode that draws out what you’re doing?Dries Hugaerts
07/13/2023, 1:54 PMfunctions.py
foos = ['a', 'b', 'c']
bars = ['d', 'e', 'f']
@parameterize_sources(
**{
f'{foo}_{bar}_sum': dict(
column_1=f'{foo}_{bar}_column',
column_2=f'{bar}_{foo}_column'
)
for foo in foos for bar in bars if foo != bar
}
)
def sum_columns(column_1: pd.Series, column_2: pd.Series) -> pd.Series:
"""
Computes the sum of two columns
"""
return column_1 + column_2
And say we have following code:
df = pd.DataFrame([[1, 2, 3, 4], [3, 4, 5, 6]], columns=['a_d_column', 'd_a_column', 'b_e_column', 'e_b_column'])
module = importlib.import_module('functions')
driver = Driver(df, module)
Then the graph would have 9 nodes, but only 2 executable: a_d_sum
and b_e_sum
When I execute driver.list_available_variables()
I get
['a_d_sum',
'a_e_sum',
'a_f_sum',
'b_d_sum',
'b_e_sum',
'b_f_sum',
'c_d_sum',
'c_e_sum',
'c_f_sum']
What we are looking for:
driver.list_executable_variables()
>['a_d_sum',
'b_e_sum']
Elijah Ben Izzy
07/13/2023, 1:57 PMElijah Ben Izzy
07/13/2023, 2:22 PMDries Hugaerts
07/13/2023, 2:59 PM@parameterize_sources(
**{
f'{foo}_{bar}_sum': dict(
column=f'{bar}_{foo}_sum',
)
for foo in foos for bar in foos if foo != bar
}
)
def minus(column: pd.Series) -> pd.Series:
"""
Computes the inverse
"""
return -column
Then these will also turn up in the list (e.g. a_b_sum, b_a_sum, ...
), however if you now try to execute this you will hit the recursion limit as "foo_bar_sum" -> "bar_foo_sum" -> "foo_bar_sum" -> …
We are able to work around this by temporarily disabling these definitions, which works as desired.
Many thanks!Elijah Ben Izzy
07/13/2023, 3:00 PMElijah Ben Izzy
07/13/2023, 3:46 PMElijah Ben Izzy
07/13/2023, 3:53 PM