Slackbot
11/07/2023, 8:44 AMElijah Ben Izzy
11/07/2023, 2:52 PMJVial
11/09/2023, 9:10 PMElijah Ben Izzy
11/10/2023, 12:10 AMres = dr.execute(["ID", "customer_id", "first_name"], ...)
res = res.dropna() # You should figure out the best way to do this -- maybe across just some columns?
3. Joining in functions:
def final_result(ID: pd.Series, customer_id: pd.Series, first_name: pd.Series, filter_name: str) -> pd.DataFrame:
df = pd.concat([ID, customer_id, first_name], axis=0)
return df[df.first_name == filter_name]
res = dr.execute(["final_results"], ...)
OTOH, it might just work! Worth a try. All it does is a concat (I think), and pandas is smart about indices:
>>> a = pd.Series(index=[1,2,3], data=['a','b','c'])
>>> b = pd.Series(index=[2,3,4], data=['e', 'f', 'g'])
>>> pd.concat([a,b], axis=1)
0 1
1 a NaN
2 b e
3 c f
4 NaN g
Elijah Ben Izzy
11/10/2023, 12:33 AM>>> def a() -> pd.Series:
... return pd.Series(index=[1,2,3], data=['a','b','c'])
...
>>> def b() -> pd.Series:
... return pd.Series(index=[2,3,4], data=['e', 'f', 'g'])
...
>>> from hamilton.ad_hoc_utils import create_temporary_module
>>> dr.execute(["a","b"])
a b
1 a NaN
2 b e
3 c f
4 NaN g
>>> dr.execute(["a","b"]).dropna()
a b
2 b e
3 c f
That said, managing indices can be a little tricky, so you may want to consider building your own results builder to handle edge cases and make it more explicit what’s happening.