-
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.
They enable one to annotate a function as loading or saving data and then having that metadata available for capture. This also removes older code -- hopefully all of it...
- Loading branch information
Showing
12 changed files
with
149 additions
and
147 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import simple_etl | ||
from hamilton_sdk import adapters | ||
|
||
from hamilton import driver | ||
|
||
tracker = adapters.HamiltonTracker( | ||
project_id=7, # modify this as needed | ||
username="[email protected]", | ||
dag_name="my_version_of_the_dag", | ||
tags={"environment": "DEV", "team": "MY_TEAM", "version": "X"}, | ||
) # note this slows down execution because there's 60 columns. | ||
# 30 columns adds about a 1 second. | ||
# 60 is therefore 2 seconds. | ||
|
||
dr = driver.Builder().with_config({}).with_modules(simple_etl).with_adapters(tracker).build() | ||
dr.display_all_functions("simple_etl.png") | ||
|
||
import time | ||
|
||
start = time.time() | ||
print(start) | ||
dr.execute(["saved_data"], inputs={"filepath": "data.csv"}) | ||
print(time.time() - start) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,37 +1,24 @@ | ||
import pandas as pd | ||
from sklearn import datasets | ||
|
||
from hamilton.htypes import DataLoaderMetadata, DataSaverMetadata | ||
from hamilton.function_modifiers import loader, saver | ||
from hamilton.io import utils as io_utils | ||
|
||
|
||
def raw_data() -> tuple[pd.DataFrame, DataLoaderMetadata]: | ||
@loader() | ||
def raw_data() -> tuple[pd.DataFrame, dict]: | ||
data = datasets.load_digits() | ||
df = pd.DataFrame(data.data, columns=[f"feature_{i}" for i in range(data.data.shape[1])]) | ||
return df, DataLoaderMetadata.from_dataframe(df) | ||
metadata = io_utils.get_dataframe_metadata(df) | ||
return df, metadata | ||
|
||
|
||
def transformed_data(raw_data: pd.DataFrame) -> pd.DataFrame: | ||
return raw_data | ||
|
||
|
||
def saved_data(transformed_data: pd.DataFrame, filepath: str) -> DataSaverMetadata: | ||
@saver() | ||
def saved_data(transformed_data: pd.DataFrame, filepath: str) -> dict: | ||
transformed_data.to_csv(filepath) | ||
return DataSaverMetadata.from_file_and_dataframe(filepath, transformed_data) | ||
|
||
|
||
if __name__ == "__main__": | ||
import __main__ as simple_etl | ||
from hamilton_sdk import adapters | ||
|
||
from hamilton import driver | ||
|
||
tracker = adapters.HamiltonTracker( | ||
project_id=7, # modify this as needed | ||
username="[email protected]", | ||
dag_name="my_version_of_the_dag", | ||
tags={"environment": "DEV", "team": "MY_TEAM", "version": "X"}, | ||
) | ||
dr = driver.Builder().with_config({}).with_modules(simple_etl).with_adapters(tracker).build() | ||
dr.display_all_functions("simple_etl.png") | ||
|
||
dr.execute(["saved_data"], inputs={"filepath": "data.csv"}) | ||
metadata = io_utils.get_file_and_dataframe_metadata(filepath, transformed_data) | ||
return metadata |
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
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
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
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
Oops, something went wrong.