From 44bd3bbbee3fc6cca8c0d92fe1fc7ec4229c6716 Mon Sep 17 00:00:00 2001 From: Cyril Amsellem Date: Wed, 6 Nov 2024 13:48:55 +1100 Subject: [PATCH 1/2] Doc update --- .../kestra/plugin/scripts/python/Script.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/plugin-script-python/src/main/java/io/kestra/plugin/scripts/python/Script.java b/plugin-script-python/src/main/java/io/kestra/plugin/scripts/python/Script.java index 719533e..e17462f 100644 --- a/plugin-script-python/src/main/java/io/kestra/plugin/scripts/python/Script.java +++ b/plugin-script-python/src/main/java/io/kestra/plugin/scripts/python/Script.java @@ -111,16 +111,18 @@ with open('{{ outputs.previousTaskId.uri }}', 'r') as f: tasks: - id: python type: io.kestra.plugin.scripts.python.Script + outputFiles: + - "myfile.txt" script: | - f = open("{{ outputDir }}/myfile.txt", "a") - f.write("Hello from a Kestra task!") - f.close() + f = open("myfile.txt", "a") + f.write("Hello from a Kestra task!") + f.close() """ ), @Example( full = true, title = """ - If you want to generate files in your script to make them available for download and use in downstream tasks, you can leverage the `{{outputDir}}` expression. Files stored in that directory will be persisted in Kestra's internal storage. The first task in this example creates a file `'myfile.txt'` and the next task can access it by leveraging the syntax `{{outputs.yourTaskId.outputFiles['yourFileName.fileExtension']}}`. + If you want to generate files in your script to make them available for download and use in downstream tasks, you can leverage the outputFiles property as shown in the example above. Files will be persisted in Kestra's internal storage. The first task in this example creates a file `'myfile.txt'` and the next task can access it by leveraging the syntax `{{outputs.yourTaskId.outputFiles['yourFileName.fileExtension']}}`. """, code = """ id: python_outputs @@ -130,19 +132,21 @@ with open('{{ outputs.previousTaskId.uri }}', 'r') as f: - id: clean_dataset type: io.kestra.plugin.scripts.python.Script containerImage: ghcr.io/kestra-io/pydata:latest + outputFiles: + - "clean_dataset.csv" script: | import pandas as pd df = pd.read_csv("https://huggingface.co/datasets/kestra/datasets/raw/main/csv/messy_dataset.csv") - + # Replace non-numeric age values with NaN df["Age"] = pd.to_numeric(df["Age"], errors="coerce") - + # mean imputation: fill NaN values with the mean age mean_age = int(df["Age"].mean()) print(f"Filling NULL values with mean: {mean_age}") df["Age"] = df["Age"].fillna(mean_age) - df.to_csv("{{ outputDir }}/clean_dataset.csv", index=False) - + df.to_csv("clean_dataset.csv", index=False) + - id: readFileFromPython type: io.kestra.plugin.scripts.shell.Commands taskRunner: From 87ce79f63184e95412f330ed77b9f38e6faf565f Mon Sep 17 00:00:00 2001 From: Cyril Amsellem Date: Wed, 6 Nov 2024 13:54:58 +1100 Subject: [PATCH 2/2] Fixed documentation: - replaced deprecated {{ outputDir }} with outputFiles property - fixed a typo with the name of the file in one of the examples --- .../src/main/java/io/kestra/plugin/scripts/python/Script.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin-script-python/src/main/java/io/kestra/plugin/scripts/python/Script.java b/plugin-script-python/src/main/java/io/kestra/plugin/scripts/python/Script.java index e17462f..3163e31 100644 --- a/plugin-script-python/src/main/java/io/kestra/plugin/scripts/python/Script.java +++ b/plugin-script-python/src/main/java/io/kestra/plugin/scripts/python/Script.java @@ -122,7 +122,7 @@ with open('{{ outputs.previousTaskId.uri }}', 'r') as f: @Example( full = true, title = """ - If you want to generate files in your script to make them available for download and use in downstream tasks, you can leverage the outputFiles property as shown in the example above. Files will be persisted in Kestra's internal storage. The first task in this example creates a file `'myfile.txt'` and the next task can access it by leveraging the syntax `{{outputs.yourTaskId.outputFiles['yourFileName.fileExtension']}}`. + If you want to generate files in your script to make them available for download and use in downstream tasks, you can leverage the `outputFiles` property as shown in the example above. Files will be persisted in Kestra's internal storage. The first task in this example creates a file `'clean_dataset.csv'` and the next task can access it by leveraging the syntax `{{outputs.yourTaskId.outputFiles['yourFileName.fileExtension']}}`. """, code = """ id: python_outputs