Skip to content

Instantly share code, notes, and snippets.

View kvnkho's full-sized avatar
👋
Feel free to message me. Contact info in profile

Kevin Kho kvnkho

👋
Feel free to message me. Contact info in profile
View GitHub Profile
# 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()
# Prefect 1.0
with Flow("basic") as flow:
e = extract()
t = transform(e)
l = load(t)
flow.run()
# Prefect 1.0 - Incorrect usage
with Flow("basic") as flow:
today = datetime.date.today()
e = extract(today)
t = transform(e)
l = load(t)
# 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)
# Prefect 2.0
@flow
def myflow():
today = datetime.date.today()
e = extract(today)
t = transform(e)
l = load(t)
# 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)
# 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:
# 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)
# 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)
# 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)