<@U0498UD24AC> please post your async issue here :...
# hamilton-help
s
@Seth Stokes please post your async issue here 🙂
s
OK, here it is
Copy code
File "C:\Users\stokes\AppData\Roaming\Python\Python39\site-packages\hamilton\graph.py", line 995, in get_upstream_nodes
    nodes, user_nodes = self.graph.get_upstream_nodes(final_vars, inputs, overrides)
    nodes, user_nodes = self.graph.get_upstream_nodes(final_vars, inputs, overrides)
    nodes, user_nodes = self.graph.get_upstream_nodes(final_vars, inputs, overrides)
    nodes, user_nodes = self.graph.get_upstream_nodes(final_vars, inputs, overrides)
    nodes, user_nodes = self.graph.get_upstream_nodes(final_vars, inputs, overrides)
    nodes, user_nodes = self.graph.get_upstream_nodes(final_vars, inputs, overrides)
    nodes, user_nodes = self.graph.get_upstream_nodes(final_vars, inputs, overrides)
  File "C:\Users\stokes\AppData\Roaming\Python\Python39\site-packages\hamilton\graph.py", line 995, in get_upstream_nodes
    return self.directional_dfs_traverse(
  File "C:\Users\stokes\AppData\Roaming\Python\Python39\site-packages\hamilton\graph.py", line 1048, in directional_dfs_traverse
    if var not in self.nodes and var not in self.config:
TypeError: unhashable type: 'HamiltonNode'
    return self.directional_dfs_traverse(
  File "C:\Users\stokes\AppData\Roaming\Python\Python39\site-packages\hamilton\graph.py", line 1048, in directional_dfs_traverse
    if var not in self.nodes and var not in self.config:
TypeError: unhashable type: 'HamiltonNode'
  File "C:\Users\stokes\AppData\Roaming\Python\Python39\site-packages\hamilton\graph.py", line 1048, in directional_dfs_traverse
    if var not in self.nodes and var not in self.config:
TypeError: unhashable type: 'HamiltonNode'
    if var not in self.nodes and var not in self.config:
TypeError: unhashable type: 'HamiltonNode'
TypeError: unhashable type: 'HamiltonNode'
👀 1
The issue fails on line 94.
s
@Seth Stokes congratulations, you’ve found a 🐛
@Seth Stokes the quick fix is to do this:
Copy code
for _break in breaks_nodes:
        b = asyncio.run(
            dr.execute([_break.name]) # <-- add .name 
        )
I’ve got a fix. Will push out tomorrow.
thank you!
Actually I’ll wait for you to validate that that is the issue — it seems to me that it is 🙂
s
Yes sir, that is a fix
👍 1
Copy code
dr = asyncio.run(
        Builder()
        .with_adapters(base.PandasDataFrameResult())
        .with_modules(__main__)
        .build()
        )
Why does the Builder also need to be awaited?
s
it’s an async builder
so the build method here is
async
👍 1
s
Can I call a list of nodes with the async driver?
Copy code
data: Dict[str, pd.DataFrame] = asyncio.run(async_dr.execute(list_of_nodes))
Erroring downstream.
Copy code
> trades_w_fee_schedule_and_expected_fee [rec_fees_trade_level.reconciliation.recon_fee_price.trades_w_fee_schedule_and_expected_fee()] encountered an error<
> Node inputs:
{'trades_w_fee_schedule': "<Task finished name='Task-82' "
                              'coro=<AsyncGraphAdap...'}
********************************************************************************
Traceback (most recent call last):
  File "C:\codebase\rec-fees-trade-level\cfee-venv\lib\site-packages\hamilton\async_driver.py", line 122, in new_fn
    await fn(**fn_kwargs) if asyncio.iscoroutinefunction(fn) else fn(**fn_kwargs)
  File "C:\codebase\rec-fees-trade-level\src\rec_fees_trade_level\reconciliation\recon_fee_price.py", line 81, in cci_trades_w_fee_schedule_and_expected_fee
    return cci_trades_w_fee_schedule.pipe(calculate_fee_func)
  File "C:\codebase\rec-fees-trade-level\cfee-venv\lib\site-packages\pandas\core\generic.py", line 6231, in pipe
    return common.pipe(self, func, *args, **kwargs)
  File "C:\codebase\rec-fees-trade-level\cfee-venv\lib\site-packages\pandas\core\common.py", line 502, in pipe
    return func(obj, *args, **kwargs)
  File "C:\codebase\rec-fees-trade-level\src\rec_fees_trade_level\allocation\apply_fees.py", line 263, in apply_fees__any
    df.loc[df.query(cond).index, "expected_fee_cols"] = ", ".join(cols)
  File "C:\codebase\rec-fees-trade-level\cfee-venv\lib\site-packages\pandas\core\indexing.py", line 911, in __setitem__
    iloc._setitem_with_indexer(indexer, value, self.name)
  File "C:\codebase\rec-fees-trade-level\cfee-venv\lib\site-packages\pandas\core\indexing.py", line 1847, in _setitem_with_indexer
    raise ValueError(
ValueError: cannot set a frame with no defined index and a scalar
ERROR:hamilton.async_driver:-------------------------------------------------------------------
s
This is something internal. It appears it’s trying to do something with a co-routine, i.e. the output of an async function. That should have been awaited.
what is
calculate_fee_func
in the function
cci_trades_w_fee_schedule_and_expected_fee
?
s
Copy code
def trades_w_fee_schedule_and_expected_fee(
    trades_w_fee_schedule: pd.DataFrame,
    calculate_fee_func: callable = apply_fees,
) -> pd.DataFrame:
    return trades_w_fee_schedule.pipe(calculate_fee_func)
Copy code
def apply_fees__any(
    df: pd.DataFrame, 
    conditions_columns: Dict[str, list] = ALL_FEE_COND_COLS
    ) -> pd.DataFrame:
    """TODO - build out function to apply fees based on `execution_type`
    Returns df with new columns `expected_fee` and `expected_fee_cols`.
    """
    assert "LOT_SIZE" in df.columns, "`LOT_SIZE` missing from columns."
    
    df = df.copy()

    for cond, cols in conditions_columns.items():
        if _exists_cols(cols, df):
            df.loc[df.query(cond).index, "expected_fee"] = df["LOT_SIZE"] * df.loc[:,  cols].sum(axis="columns")
            df.loc[df.query(cond).index, "expected_fee_cols"] = ", ".join(cols)

    return df
s
Yeah so
trades_w_fee_schedule
is somehow an unawaited co-routine; from the trace you provided — though I’m confused a little by it.
Resolution here: In async - the top of the stack trace objects will likely always be co-routines. Best way to debug when using the AsyncDriver is to request the input that is erroring and inspect that. In this case it was empty.
s
Is there any reason
GracefulErrorAdapter(error_to_catch=ValueError),
wouldn't work with the async driver? Was hoping to use that to easily debug from the results that finished correctly.
s
Is a ValueError being thrown? Or another error?
s
Yes ValueError
Same as yesterday.
ValueError: cannot set a frame with no defined index and a scalar
s
Yep confirmed - the behavior. Let me look at the code.
Yeah looks like AsyncDriver is missing support for that right now
s
Ok makes sense then. Thank you.