-
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.
- Loading branch information
1 parent
a28706e
commit 0c41502
Showing
2 changed files
with
303 additions
and
3 deletions.
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,39 @@ | ||
import pandas as pd | ||
|
||
from hamilton.function_modifiers import with_columns | ||
|
||
|
||
def initial_df() -> pd.DataFrame: | ||
return pd.DataFrame({"col_1": [1, 2, 3, 4], "col_2": [11, 12, 13, 14], "col_3": [1, 1, 1, 1]}) | ||
|
||
|
||
def substract_1_from_2(col_1: pd.Series, col_2: pd.Series) -> pd.Series: | ||
return col_2 - col_1 | ||
|
||
|
||
def multiply_3_by_5(col_3: pd.Series) -> pd.Series: | ||
return col_3 * 5 | ||
|
||
|
||
@with_columns( | ||
substract_1_from_2, | ||
multiply_3_by_5, | ||
columns_to_pass=["col_1", "col_2", "col_3"], | ||
select=["substract_1_from_2", "multiply_3_by_5"], | ||
namespace="some_subdag", | ||
) | ||
def final_df(initial_df: pd.DataFrame) -> pd.DataFrame: | ||
return initial_df | ||
|
||
|
||
def col_3(initial_df: pd.DataFrame) -> pd.Series: | ||
return pd.Series([0, 2, 4, 6]) | ||
|
||
|
||
@with_columns( | ||
col_3, | ||
pass_dataframe_as="initial_df", | ||
select=["col_3", "multiply_3_by_5"], | ||
) | ||
def final_df_2(initial_df: pd.DataFrame) -> pd.DataFrame: | ||
return initial_df |