Why does this fail on `import` and not execution i...
# hamilton-help
s
Why does this fail on
import
and not execution if I forget the
**
for
parameterize
line
226
?
Copy code
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [1], in <cell line: 7>()
      4 import pandas as pd
      5 from hamilton import driver, base
----> 7 import cme
--> 226 @parameterize({
    227     f"is_{exec_type}": {"raw_fee_type": source("raw_fee_type"), "search_exec_type": value(exec_type)}
    228     for exec_type in ["tas", "block", "efp", "efr", "eoo"]
    229 })
    230 def execution_types(raw_fee_type: pd.Series, search_exec_type: str) -> pd.Series:
    231     return raw_fee_type.str.contains(search_exec_type, na=False)
    234 def member_status(raw_fee_type: pd.Series) -> pd.Series:

TypeError: __init__() takes 1 positional argument but 2 were given
Note: not urgent as I realized the
**
was the issue, more of a curiosity.
👍 1
t
TL;DR: 1. Hamilton decorators are classes 2. Python decorators are bound to functions when importing a module 3. Invalid decorator definition will throw an error at import time ## Details Function modifiers are classes used as decorators. In the case of
@parameterize
, the
__init__
is:
Copy code
def __init__(
        self,
        **parametrization: Union[
            Dict[str, ParametrizedDependency],
            Tuple[Dict[str, ParametrizedDependency], str],
        ],
    )
It has 1 positional argument (
self
) and only accepts keyword arguments (kwargs) collected by
**parametrization
. Therefore,
@parameterize
can't accept a
dict()
, but can receive an unpacked dict (
**dict()
). When importing the module, the class
parameterize
needs to be instantiated and bound to its function (here
execution_types()
). In other words, it's a "standard Python error" and isn't specific to Hamilton or how the dataflow is defined, which would be caught at the
Driver
build or execution.
👍 1