This message was deleted.
# hamilton-help
s
This message was deleted.
e
Hey! A few possible ways, but first, a question. Is the reason you’re doing this so that you don’t have to import hamilton to use your functions? E.G. so that you can define your functions in a module, then decorate them later?
b
Yes that's exactly it.
The decorators and data loading gets messy enough that it seems worth it to abstract out the business logic even more.
e
So, we designed it with the idea that the way the functions are used would live fairly close to their definitions — thus you wouldn’t have to look in two places to figure out how they should be used. So, a few possibilities: 1. define the data loading functions as helpers (in their own module), and import them for use in your functions. Then attach functions that have decorators to them, that just call out to those functions. This is quite helpful for reuse:
Copy code
from another_module_with_reusable_logic_but_not_functions import load_data

@parameterize(
    dataset_1={"path" : source("dataset_1_path")}, 
    dataset_2=...)
def dataset(path: str) -> pd.DataFrame:
    load_data(path)
2. Use
ad_hoc_utils
Copy code
from hamilton.ad_hoc_utils import create_temporary_module

what_do_i_do_with_this = parameterize(**{"new_func_name": source(arg1etc)})(my_func)

dr = driver.Driver(config, create_temporary_module(what_do_i_do_with_this, another_func, ...)
3. Actually, what you’re doing will (likely, haven’t tested it out yet), just work. That said, its a bit of an implementation detail as to how, but its pretty ironed out by now. Why? All these decorators do is add some markers to the function. As long as they’re marked prior to the driver constructing the graph, you should be good.
I (personally) prefer (1) — colocating reusable logic, so long as you don’t have a dependency limitation on imports. If you do, then you can see a prior discussion (related) here: https://hamilton-opensource.slack.com/archives/C03M33QB4M8/p1666827158031259
b
Thanks, that's helpful and I see your point about (1).
e
Awesome! Let me know if you have any other issues 🙂