Slackbot
11/04/2023, 9:18 PMmiek
11/04/2023, 9:23 PMElijah Ben Izzy
11/04/2023, 10:35 PM@subdag
— its very powerful, and was envisioned initially to handle exactly this — computations across different granularities. Here are the docs: https://hamilton.dagworks.io/en/latest/reference/decorators/subdag/.
We actually have an example that does something very similar to what you’re interested in. In this case, we’re utilizing the ability to run a common set of computation across two dimension (region/granularity, granularity being exactly what you described).
https://github.com/DAGWorks-Inc/hamilton/tree/main/examples/reusing_functions
The way to think about this is this is a nice way to reuse a group of operations while keeping it fine-grained. If you want to get really fancy we have @parameterized_subdag
(in case you don’t like copy/pasting), and @resolve
(to make the parameters configuration-driven), but I’d see how far subdag can get you.
That said, there is another approach that you may or may not like, depending on how much you want individual functions to map to columns/datapoints. You could always:
1. Create a helper function that does these aggregations on a dataframe
2. Call it for each granularity, having the function input a dataframe/join a set of columns.
So yeah, if you want the same fine-grained approach that Hamilton likes, I’d suggest subdag — if you want to just run a bunch of aggregations, dataframe manipulations aren’t crazy.miek
11/04/2023, 11:32 PMElijah Ben Izzy
11/04/2023, 11:44 PMmiek
11/05/2023, 12:57 AM@paramiterized_subdag
might be better…let me study those nextElijah Ben Izzy
11/05/2023, 1:12 AMmiek
11/05/2023, 1:15 AMElijah Ben Izzy
11/05/2023, 1:16 AMmiek
11/05/2023, 1:16 AMmiek
11/09/2023, 12:01 AMElijah Ben Izzy
11/09/2023, 12:04 AMElijah Ben Izzy
11/09/2023, 12:04 AMElijah Ben Izzy
11/09/2023, 12:06 AM@resolve
takes in two parameters — when
will be fixed, and decorate_with
is a function that gives the decorator, given certain config parameters
2. It refers to the “Config” in the driver — these config parameters in the function will be pulled from that. Note its different than the “inputs” — “config” is done at runtime
3. You need to set power-user mode to true (have to prove that you’re serious 😆 )miek
11/09/2023, 12:09 AMmiek
11/09/2023, 12:09 AMElijah Ben Izzy
11/09/2023, 12:10 AM