.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto/core/flyte_basics/documented_workflow.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_core_flyte_basics_documented_workflow.py: Add Docstrings to Workflows --------------------------- Documented code helps enhance the readability of the code. Flyte supports docstrings to document your code. Docstrings are stored in FlyteAdmin and shown on the UI in the launch form. This example demonstrates the various ways in which you can document your Flyte workflow. The example workflow accepts a DataFrame and data class. We send a record that needs to be appended to the DataFrame through a data class. .. GENERATED FROM PYTHON SOURCE LINES 13-14 Let's import the libraries. .. GENERATED FROM PYTHON SOURCE LINES 14-20 .. code-block:: default from dataclasses import dataclass import pandas as pd from dataclasses_json import dataclass_json from flytekit import task, workflow .. GENERATED FROM PYTHON SOURCE LINES 21-22 We define a dataclass. .. GENERATED FROM PYTHON SOURCE LINES 22-29 .. code-block:: default @dataclass_json @dataclass class PandasData(object): id: int = 3 name: str = "Bonnie" .. GENERATED FROM PYTHON SOURCE LINES 30-31 Next, we define a task that appends data to the DataFrame. .. GENERATED FROM PYTHON SOURCE LINES 31-37 .. code-block:: default @task def add_data(df: pd.DataFrame, data: PandasData) -> pd.DataFrame: df = df.append({"id": data.id, "name": data.name}, ignore_index=True) return df .. GENERATED FROM PYTHON SOURCE LINES 38-46 Sphinx-style Docstring ====================== An example to demonstrate Sphinx-style docstring. The first block of the docstring is a one-liner about the workflow. The second block of the docstring consists of a detailed description. The third block of the docstring describes the parameters and return type. .. GENERATED FROM PYTHON SOURCE LINES 46-61 .. code-block:: default @workflow def sphinx_docstring(df: pd.DataFrame, data: PandasData = PandasData()) -> pd.DataFrame: """ Showcase Sphinx-style docstring. This workflow accepts a DataFrame and data class. It calls a task that appends the user-sent record to the DataFrame. :param df: Pandas DataFrame :param data: A data class pertaining to the new record to be stored in the DataFrame :return: Pandas DataFrame """ return add_data(df=df, data=data) .. GENERATED FROM PYTHON SOURCE LINES 62-71 NumPy-style Docstring ====================== An example to demonstrate NumPy-style docstring. The first block of the docstring is a one-liner about the workflow. The second block of the docstring consists of a detailed description. The third block of the docstring describes all the parameters along with their data types. The fourth block of the docstring descibes the return type along with its data type. .. GENERATED FROM PYTHON SOURCE LINES 71-94 .. code-block:: default @workflow def numpy_docstring(df: pd.DataFrame, data: PandasData = PandasData()) -> pd.DataFrame: """ Showcase NumPy-style docstring. This workflow accepts a DataFrame and data class. It calls a task that appends the user-sent record to the DataFrame. Parameters ---------- df: pd.DataFrame Pandas DataFrame data: Dataclass A data class pertaining to the new record to be stored in the DataFrame Returns ------- out : pd.DataFrame Pandas DataFrame """ return add_data(df=df, data=data) .. GENERATED FROM PYTHON SOURCE LINES 95-103 Google-style Docstring ====================== An example to demonstrate Google-style docstring. The first block of the docstring is a one-liner about the workflow. The second block of the docstring consists of a detailed description. The third block of the docstring describes the parameters and return type along with their data types. .. GENERATED FROM PYTHON SOURCE LINES 103-120 .. code-block:: default @workflow def google_docstring(df: pd.DataFrame, data: PandasData = PandasData()) -> pd.DataFrame: """ Showcase Google-style docstring. This workflow accepts a DataFrame and data class. It calls a task that appends the user-sent record to the DataFrame. Args: df(pd.DataFrame): Pandas DataFrame data(Dataclass): A data class pertaining to the new record to be stored in the DataFrame Returns: pd.DataFrame: Pandas DataFrame """ return add_data(df=df, data=data) .. GENERATED FROM PYTHON SOURCE LINES 121-122 Lastly, we can run the workflow locally. .. GENERATED FROM PYTHON SOURCE LINES 122-133 .. code-block:: default if __name__ == "__main__": print(f"Running {__file__} main...") print( f"Running sphinx_docstring(), modified DataFrame is {sphinx_docstring(df=pd.DataFrame(data={'id': [1, 2], 'name': ['John', 'Meghan']}),data=PandasData(id=3, name='Bonnie'))}" ) print( f"Running numpy_docstring(), modified DataFrame is {numpy_docstring(df=pd.DataFrame(data={'id': [1, 2], 'name': ['John', 'Meghan']}),data=PandasData(id=3, name='Bonnie'))}" ) print( f"Running google_docstring(), modified DataFrame is {google_docstring(df=pd.DataFrame(data={'id': [1, 2], 'name': ['John', 'Meghan']}),data=PandasData(id=3, name='Bonnie'))}" ) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_core_flyte_basics_documented_workflow.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: documented_workflow.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: documented_workflow.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_