-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional integration tests for async pipe_input, pipe_output and mutate.
- Loading branch information
1 parent
eb60d5d
commit 28c9d14
Showing
3 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import asyncio | ||
|
||
import pandas as pd | ||
|
||
from hamilton.function_modifiers import apply_to, mutate | ||
|
||
|
||
def data_mutate(data_input: pd.DataFrame) -> pd.DataFrame: | ||
return data_input | ||
|
||
|
||
@mutate(apply_to(data_mutate).when(groupby="a")) | ||
async def _groupby_a_mutate(d: pd.DataFrame) -> pd.DataFrame: | ||
await asyncio.sleep(0.0001) | ||
return d.groupby("a").sum().reset_index() | ||
|
||
|
||
@mutate(apply_to(data_mutate).when_not(groupby="a")) | ||
async def _groupby_b_mutate(d: pd.DataFrame) -> pd.DataFrame: | ||
await asyncio.sleep(0.0001) | ||
return d.groupby("b").sum().reset_index() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import asyncio | ||
|
||
import pandas as pd | ||
|
||
from hamilton.function_modifiers import pipe_input, pipe_output, step | ||
|
||
# async def data_input() -> pd.DataFrame: | ||
# await asyncio.sleep(0.0001) | ||
# return | ||
|
||
|
||
async def _groupby_a(d: pd.DataFrame) -> pd.DataFrame: | ||
await asyncio.sleep(0.0001) | ||
return d.groupby("a").sum().reset_index() | ||
|
||
|
||
async def _groupby_b(d: pd.DataFrame) -> pd.DataFrame: | ||
await asyncio.sleep(0.0001) | ||
return d.groupby("b").sum().reset_index() | ||
|
||
|
||
@pipe_input( | ||
step(_groupby_a).when(groupby="a"), | ||
step(_groupby_b).when_not(groupby="a"), | ||
) | ||
def data_pipe_input(data_input: pd.DataFrame) -> pd.DataFrame: | ||
return data_input | ||
|
||
|
||
@pipe_output( | ||
step(_groupby_a).when(groupby="a"), | ||
step(_groupby_b).when_not(groupby="a"), | ||
) | ||
def data_pipe_output(data_input: pd.DataFrame) -> pd.DataFrame: | ||
return data_input |