This message was deleted.
# hamilton-help
s
This message was deleted.
👀 1
e
Ok, I think I see what’s going on here. So, you’re not actually supposed to call other hamilton functions within a hamilton function. Rather, we use a dependency injection of sorts — its a bit clever.
So, when you call out to
get_patterns
in
get_filepaths
, instead, you want
get_filepaths
to depend on
get_patterns
E.G.
Copy code
def filepaths(patterns: List[str]) -> List:
    """returns all filepaths that match pattern"""
    paths = get_matching_paths(patterns)
    return paths
Copy code
@config.when(data="cost")
def patterns__cost(org: int, provider: str, lookback: int) -> List[str]:
    """Retruns patterns that match for cost data"""
    patterns = []
    # some patterns logic...
    return patterns


@config.when(data="utilisation")
def patterns__util(org: int, provider: str, lookback: int) -> List[str]:
    """Retruns patterns that match for utilisation data"""
    patterns = []
    # some patterns logic...
    return patterns
and
load_data
should be something like this:
Copy code
def data_loaded(spark: SparkSession, filepaths: List[str]):
    ...
So basically hamilton controls the DAG but you define the function — that way, you never have to wire through your inputs to the function!
Note I’ve also made a change to the way you name them that should make it easier to follow — I suggest using nouns to name your functions, rather than verbs. The trick to know is that each function corresponds to a set of artifacts, and your definition of them both tells you how they should be computed and what artifact they create.
Also the specific reason that
get_patterns
wasn’t being recognized is cause Hamilton doesn’t actually rename the function — it just sets the name of the nodes it creates. So, the functions were still called
get_patterns__util
, and when you called
get_patterns
python couldn’t find them 🙂
a
Oh I see. So then even `get_matching_paths`should be changed right. I can simply drop the
filepaths
function I guess. Thanks Elijah!
👍 1
e
Up to you! But the way to think is that each function is a node, not a piece that you call in a bunch of different ways.
a
Also, can we define generators instead of functions in hamilton?
e
Currently not but see https://github.com/DAGWorks-Inc/hamilton/issues/90 for a discussion! What’s your use-case?
a
Ok, will have a look. I don’t have a very specific use-case, probably can workout with normal iterators.
e
Cool — let me know if you have any cases that need generators and I’m happy to discuss
👍 1