Created
December 18, 2024 04:37
-
-
Save elijahbenizzy/2b668f1a871a1f94ef733ec49aacbbdf to your computer and use it in GitHub Desktop.
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
from datetime import datetime | |
from hamilton.function_modifiers import config, extract_fields, pipe_output, step | |
def _convert_US_to_datatime(date: str) -> datetime: | |
return datetime.strptime(date, "%m/%d/%Y") | |
def _convert_EMEA_to_datatime(date: str) -> datetime: | |
return datetime.strptime(date, "%d/%m/%Y") | |
@pipe_output(step(_convert_EMEA_to_datatime)) | |
@extract_fields({"a": str, "b": str, "c": str}) | |
@config.when(region="EMEA") | |
def some_dictionary_node__ddmmyy() -> dict: | |
return { | |
"a": "31/1/2000", | |
"b": "28/2/2010", | |
"c": "30/3/2020", | |
} | |
@pipe_output(step(_convert_US_to_datatime)) | |
@extract_fields({"a": str, "b": str, "c": str}) | |
@config.when(region="US") | |
def some_dictionary_node__mmddyy() -> dict: | |
return { | |
"a": "1/31/2000", | |
"b": "2/28/2010", | |
"c": "3/30/2020", | |
} | |
def ab_period(a: datetime, b: datetime) -> int: | |
return (b - a).days | |
def ac_period(a: datetime, c: datetime) -> int: | |
return (c - a).days | |
def bc_period(b: datetime, c: datetime) -> int: | |
return (c - b).days | |
if __name__ == "__main__": | |
import __main__ | |
from hamilton import drive | |
dr = driver.Builder().with_modules(__main__).with_config({"region": "US"}).build() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment