小编Jus*_*zas的帖子

气流:当某些上游被短路跳过时运行任务

我有一个任务,我将调用final它具有多个上游连接。当ShortCircuitOperator此任务跳过上游之一时,也会跳过。我不希望final任务被跳过,因为它必须报告 DAG 成功。

为了避免它被跳过,我使用了trigger_rule='all_done',但它仍然被跳过。

如果我使用BranchPythonOperator而不是ShortCircuitOperator final任务不会被跳过。看起来分支工作流可能是一个解决方案,即使不是最优的,但现在final不会考虑上游任务的失败。

如何让它仅在上游成功或跳过时运行?

示例短路 DAG:

from airflow import DAG
from airflow.operators.dummy_operator import DummyOperator
from airflow.operators.python_operator import ShortCircuitOperator
from datetime import datetime
from random import randint

default_args = {
    'owner': 'airflow',
    'start_date': datetime(2018, 8, 1)}

dag = DAG(
    'shortcircuit_test',
    default_args=default_args,
    schedule_interval='* * * * *',
    catchup=False)

def shortcircuit_fn():
    return randint(0, 1) == 1

task_1 = DummyOperator(dag=dag, task_id='task_1')
task_2 = DummyOperator(dag=dag, task_id='task_2')

work = …
Run Code Online (Sandbox Code Playgroud)

airflow

10
推荐指数
3
解决办法
1万
查看次数

在Python中将长方法链分成多行

我正在学习Python和Pandas,但是我经常遇到很多方法调用。我知道如何以一种编译的方式破坏列表和操作符链,但是我找不到以一种不作弊的方式破坏方法链的方法。

在Google中有很多分解运算符链和列表的示例,但是我找不到适合方法链的任何东西。

在Python 3中将一长串方法调用分成多行的最佳方法是什么?

像这样说一行:

t_values = df_grouped_by_day.sort_values('day_of_week').groupby(['day_of_week', 'day_of_week_name'])['Show_up'].apply(lambda sample: ttest_ind(population, sample)).reset_index()
Run Code Online (Sandbox Code Playgroud)

python python-3.x pandas

4
推荐指数
2
解决办法
281
查看次数

标签 统计

airflow ×1

pandas ×1

python ×1

python-3.x ×1