This file contains hidden or 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
| # case 1: without index | |
| df[df["a"]=="red"]["c"].sum() | |
| # case 2: with "a" as index | |
| idf = df.set_index("a") | |
| idf.loc["red"]["c"].sum() |
This file contains hidden or 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
| # Prefect 1.0 | |
| with Flow("basic") as flow: | |
| e = extract() | |
| t = transform(e) | |
| l = load(t) | |
| flow.run() |
This file contains hidden or 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
| # Prefect 1.0 - Incorrect usage | |
| with Flow("basic") as flow: | |
| today = datetime.date.today() | |
| e = extract(today) | |
| t = transform(e) | |
| l = load(t) |
This file contains hidden or 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
| # Prefect 1.0 | |
| @task | |
| def get_today(): | |
| return datetime.date.today() | |
| with Flow("basic") as flow: | |
| today = get_today() | |
| e = extract(today) | |
| t = transform(e) | |
| l = load(t) |
This file contains hidden or 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
| # Prefect 2.0 | |
| @flow | |
| def myflow(): | |
| today = datetime.date.today() | |
| e = extract(today) | |
| t = transform(e) | |
| l = load(t) |
This file contains hidden or 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
| # Prefect 1.0 - Incorrect usage | |
| with Flow("basic") as flow: | |
| today = Parameter("today", default=datetime.date.today()) | |
| e = extract(today) | |
| t = transform(e) | |
| l = load(t) |
This file contains hidden or 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
| # Prefect 1.0 | |
| @task | |
| def get_date(day: str): | |
| if day == "today": | |
| return datetime.date.today() | |
| else: | |
| # assume a string came in | |
| return datetime.datetime.strptime(day, '%Y-%m-%d').date() | |
| with Flow("basic") as flow: |
This file contains hidden or 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
| # Prefect 2.0 | |
| @flow | |
| def myflow(today: datetime.date = None): | |
| today_parsed = today or datetime.date.today() | |
| e = extract(today_parsed) | |
| t = transform(e) | |
| l = load(t) |
This file contains hidden or 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
| # Prefect 1.0 - Incorrect Usage | |
| with Flow("basic") as flow: | |
| e = extract() | |
| cond = check_condition(e) | |
| if cond == True: | |
| t = transform1(e) | |
| else: | |
| t = transform2(e) | |
| l = load(t) |
This file contains hidden or 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
| # Prefect 1.0 | |
| with Flow("basic") as flow: | |
| e = extract() | |
| cond = check_condition() | |
| with case(cond, True): | |
| t1 = transform1(e) | |
| with case(cond, False): | |
| t2 = transform2(e) | |
| t = merge(t1,t2) | |
| l = load(t) |