Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@task
def y():
return "y"
@task(
cache_for=datetime.timedelta(days=10),
cache_validator=partial_parameters_only(["x"]),
result_handler=JSONResultHandler(),
)
def cached_task(x, y):
pass
@prefect.task(name="test")
def raise_error():
raise NameError("I don't exist")
@prefect.task(cache_for=timedelta(minutes=10))
def tt(foo):
pass
@task(name="Big Name", checkpoint=True, result_handler=S3ResultHandler(bucket="blob"))
def terminal_task():
pass
@task
def skip_task():
raise prefect.engine.signals.SKIP("not today")
@task(cache_for=datetime.timedelta(minutes=1, seconds=30))
def return_random_number():
return random.random()
@task(max_retries=3, retry_delay=timedelta(seconds=0))
def randomly_fail():
x = random.random()
if x > 0.7:
raise ValueError("x is too large")
@task
def read_csv(
rootdir: str, table_name: str, nrows: int = None, exclude_cols: List[str] = None
):
"""
Read the contents of a CSV into a Pandas DataFrame.
This is built specifically for the file structure of the Lahman database.
Args:
- rootdir (str): name of the top-level directory where the data is stored
- table_name (str): name of the data table to be retrieved
- nrows (int, optional): defaults to all rows; otherwise, number of rows to load
- exclude_cols (List[str], optional): columns to be excluded, by name
Returns:
- pd.DataFrame: the contents of the CSV
@task
def impute(data: np.ndarray, replacement_dict: Dict[Any, Any]) -> np.ndarray:
"""
Replace any instances of a set of values with corresponding new values.
The replacements are provided in a dictionary.
The keys are the values to be replaced,
and the values are the values to replace with.
Args:
- data (np.ndarray): data in which the replacements should be made
- replacement_dict (Dict[Any, Any]): what to replace, and what to replace it with
Returns:
- np.ndarray: data with values replaced
"""
for old, new in replacement_dict.items():