You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/01/26 09:42:06 UTC
[GitHub] [airflow] VBhojawala opened a new pull request #13912: PythonOperator decorator @python_task
VBhojawala opened a new pull request #13912:
URL: https://github.com/apache/airflow/pull/13912
Added @python_task decorator for PythonOperator which can be used as shown in following example
``` python
from airflow.models import DAG
import os
from airflow.operators.python import python_task, PythonOperator
from airflow.utils.dates import days_ago
default_args = {'start_date': days_ago(1)}
dag_name = os.path.splitext(os.path.basename(__file__))[0]
@python_task
def some_py_task(name):
""" some py task """
print(f'Inside Python Task name: {name}')
def some_other_task(name):
""" some other task"""
print(f'Inside {name} Task')
with DAG(dag_name, default_args=default_args) as dag:
t1 = some_py_task(task_id='task1')('Python Task 1')
t2 = some_py_task(task_id='task2')('Python Task 2')
t3 = PythonOperator(python_callable=some_other_task, task_id='task3', op_args=['task3'])
t1 >> t2 >> t3
```
![Screenshot from 2021-01-26 14-54-47](https://user-images.githubusercontent.com/11897651/105826324-a200a480-5fe6-11eb-92cc-d7337fe367ad.png)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] turbaszek removed a comment on pull request #13912: PythonOperator decorator @python_task
Posted by GitBox <gi...@apache.org>.
turbaszek removed a comment on pull request #13912:
URL: https://github.com/apache/airflow/pull/13912#issuecomment-767474405
I'm afraid this already exists:
https://github.com/apache/airflow/blob/8723b1feb82339d7a4ba5b40a6c4d4bbb995a4f9/airflow/operators/python.py#L256-L261
See docs:
https://airflow.apache.org/docs/apache-airflow/stable/tutorial_taskflow_api.html
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] VBhojawala closed pull request #13912: PythonOperator decorator @python_task
Posted by GitBox <gi...@apache.org>.
VBhojawala closed pull request #13912:
URL: https://github.com/apache/airflow/pull/13912
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] VBhojawala removed a comment on pull request #13912: PythonOperator decorator @python_task
Posted by GitBox <gi...@apache.org>.
VBhojawala removed a comment on pull request #13912:
URL: https://github.com/apache/airflow/pull/13912#issuecomment-767487249
@task decorator currently does not support task ordering and does not returns PythonOperator instance.
For example following dag will give
``` python
from airflow.models import DAG
import os
from airflow.operators.python import PythonOperator, task
from airflow.utils.dates import days_ago
default_args = {'start_date': days_ago(1)}
dag_name = os.path.splitext(os.path.basename(__file__))[0]
@task
def some_py_task(name):
""" some py task """
print(f'Inside Python Task name: {name}')
def some_other_task(name):
""" some other task"""
print(f'Inside {name} Task')
with DAG(dag_name, default_args=default_args) as dag:
t1 = some_other_task('task1')
t2 = some_other_task('task2')
t3 = PythonOperator(python_callable=some_other_task, task_id='task3', op_args=['task3'])
t1 >> t2 >> t3
```
![Screenshot from 2021-01-26 17-07-34](https://user-images.githubusercontent.com/11897651/105840504-20fed880-5ff9-11eb-8106-092fb8563610.png)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] turbaszek commented on pull request #13912: PythonOperator decorator @python_task
Posted by GitBox <gi...@apache.org>.
turbaszek commented on pull request #13912:
URL: https://github.com/apache/airflow/pull/13912#issuecomment-767474405
I'm afraid this already exists:
https://github.com/apache/airflow/blob/8723b1feb82339d7a4ba5b40a6c4d4bbb995a4f9/airflow/operators/python.py#L256-L261
See docs:
https://airflow.apache.org/docs/apache-airflow/stable/tutorial_taskflow_api.html
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] VBhojawala commented on pull request #13912: PythonOperator decorator @python_task
Posted by GitBox <gi...@apache.org>.
VBhojawala commented on pull request #13912:
URL: https://github.com/apache/airflow/pull/13912#issuecomment-767487249
@task decorator currently does not support task ordering and does not returns PythonOperator instance.
For example following dag will give
``` python
from airflow.models import DAG
import os
from airflow.operators.python import PythonOperator, task
from airflow.utils.dates import days_ago
default_args = {'start_date': days_ago(1)}
dag_name = os.path.splitext(os.path.basename(__file__))[0]
@task
def some_py_task(name):
""" some py task """
print(f'Inside Python Task name: {name}')
def some_other_task(name):
""" some other task"""
print(f'Inside {name} Task')
with DAG(dag_name, default_args=default_args) as dag:
t1 = some_other_task('task1')
t2 = some_other_task('task2')
t3 = PythonOperator(python_callable=some_other_task, task_id='task3', op_args=['task3'])
t1 >> t2 >> t3
```
![Screenshot from 2021-01-26 17-07-34](https://user-images.githubusercontent.com/11897651/105840504-20fed880-5ff9-11eb-8106-092fb8563610.png)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org