Repository navigation
partial wrapper for Task #12565
Replies: 1 comment
|
Yes, from functools import partial
import pandas as pd
from prefect import flow, task
@task
def easy_task(df: pd.DataFrame) -> pd.DataFrame:
return df + 1
@task
def task_require_argument(df: pd.DataFrame, const: int) -> pd.DataFrame:
return df * const
@flow
def pipeline(df, tasks):
return [t(df) for t in tasks]
df = pd.DataFrame({"value": [1, 2]})
results = pipeline(df, [easy_task, partial(task_require_argument, const=3)])
assert results[0]["value"].tolist() == [2, 3]
assert results[1]["value"].tolist() == [3, 6]I ran this against a real temporary local Prefect API with Prefect 2.20.25, pandas 2.2.3, and Python 3.12.14 (Pydantic 2.10.6, AnyIO 4.8.0). Both tasks ran and the bound These values are callable task instances or partials, rather than |
Uh oh!
There was an error while loading. Please reload this page.
Is it possible to do equivalent
partialoperations on a Prefect taskFor example, I have a flow, and I want to pass some tasks as an input argument, but some of the tasks might require additional arguments which I need to specify before hand.
All reactions