Skip to content

Instantly share code, notes, and snippets.

@oguiza
Last active June 20, 2022 10:55
Show Gist options
  • Save oguiza/7d4d2e5152b7537af4b647274b01b3ac to your computer and use it in GitHub Desktop.
Save oguiza/7d4d2e5152b7537af4b647274b01b3ac to your computer and use it in GitHub Desktop.
Data_pipeline.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "# Building pipelines with fastcore"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "⚠️If you run this notebook, cells using %%file will create a python script in the folder where you are running the notebook. Remember to delete them."
},
{
"metadata": {},
"cell_type": "markdown",
"source": "# Approach 1 works"
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:32:45.737931Z",
"end_time": "2022-06-20T10:32:45.751384Z"
}
},
"cell_type": "markdown",
"source": "When we \"normal\" functions to a function using @call_parse it works great."
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:52:05.412613Z",
"end_time": "2022-06-20T10:52:05.460348Z"
},
"trusted": true
},
"cell_type": "code",
"source": "%%file func1.py\nfrom fastcore.script import *\n\ndef func1(\n a:int, # param a\n b:int, # param b\n): return a + b",
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": "Overwriting func1.py\n",
"name": "stdout"
}
]
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:52:05.887182Z",
"end_time": "2022-06-20T10:52:05.899610Z"
},
"trusted": true
},
"cell_type": "code",
"source": "%%file func2.py\nfrom fastcore.script import *\n\ndef func2(\n c:int, # param c\n d:int, # param d\n): return c + d",
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": "Overwriting func2.py\n",
"name": "stdout"
}
]
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:52:06.848933Z",
"end_time": "2022-06-20T10:52:06.861455Z"
},
"trusted": true
},
"cell_type": "code",
"source": "%%file func3.py\nfrom func1 import func1 # this function doesn't use @call_parse\nfrom func2 import func2 # this function doesn't use @call_parse\nfrom fastcore.script import *\n\n@call_parse\ndef pipeline(a, b, d):\n c = func1(a, b)\n e = func2(c, d)\n return e",
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"text": "Overwriting func3.py\n",
"name": "stdout"
}
]
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:52:07.716111Z",
"end_time": "2022-06-20T10:52:11.777567Z"
},
"trusted": true
},
"cell_type": "code",
"source": "from func3 import pipeline\npipeline(2, 3, 4)",
"execution_count": 4,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 4,
"data": {
"text/plain": "9"
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "# Approach 2 doesn't work"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "However, if you pass functions that use @call_parse, it throws an error:"
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:52:11.786727Z",
"end_time": "2022-06-20T10:52:11.798418Z"
},
"trusted": true
},
"cell_type": "code",
"source": "%%file script1.py\nfrom fastcore.script import *\n\n@call_parse\ndef func1(\n a:int, # param a\n b:int, # param b\n): return a + b",
"execution_count": 5,
"outputs": [
{
"output_type": "stream",
"text": "Overwriting script1.py\n",
"name": "stdout"
}
]
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:52:11.807404Z",
"end_time": "2022-06-20T10:52:11.824079Z"
},
"trusted": true
},
"cell_type": "code",
"source": "%%file script2.py\nfrom fastcore.script import *\n\n@call_parse\ndef func2(\n c:int, # param c\n d:int, # param d\n): return c + d",
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"text": "Overwriting script2.py\n",
"name": "stdout"
}
]
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:52:12.750293Z",
"end_time": "2022-06-20T10:52:12.763768Z"
},
"trusted": true
},
"cell_type": "code",
"source": "%%file script3.py\nfrom script1 import func1 # this function uses @call_parse\nfrom script2 import func2 # this function uses @call_parse\nfrom fastcore.script import *\n\n@call_parse\ndef pipeline(a, b, d):\n c = func1(a, b)\n e = func2(c, d)\n return e",
"execution_count": 7,
"outputs": [
{
"output_type": "stream",
"text": "Overwriting script3.py\n",
"name": "stdout"
}
]
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:52:17.263656Z",
"end_time": "2022-06-20T10:52:24.151188Z"
},
"trusted": true
},
"cell_type": "code",
"source": "from script3 import pipeline\npipeline(2, 3, 4)",
"execution_count": 8,
"outputs": [
{
"output_type": "stream",
"text": "usage: ipykernel_launcher.py [-h] a b\nipykernel_launcher.py: error: argument a: invalid int value: '/Users/nacho/Library/Jupyter/runtime/kernel-87e18ef9-d8b7-4e44-9355-73c705ac0d99.json'\n",
"name": "stderr"
},
{
"output_type": "error",
"ename": "AssertionError",
"evalue": "",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/argparse.py:2483\u001b[0m, in \u001b[0;36mArgumentParser._get_value\u001b[0;34m(self, action, arg_string)\u001b[0m\n\u001b[1;32m 2482\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m-> 2483\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mtype_func\u001b[49m\u001b[43m(\u001b[49m\u001b[43marg_string\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2485\u001b[0m \u001b[38;5;66;03m# ArgumentTypeErrors indicate errors\u001b[39;00m\n",
"\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: '/Users/nacho/Library/Jupyter/runtime/kernel-87e18ef9-d8b7-4e44-9355-73c705ac0d99.json'",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mArgumentError\u001b[0m Traceback (most recent call last)",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/argparse.py:1858\u001b[0m, in \u001b[0;36mArgumentParser.parse_known_args\u001b[0;34m(self, args, namespace)\u001b[0m\n\u001b[1;32m 1857\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m-> 1858\u001b[0m namespace, args \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parse_known_args\u001b[49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnamespace\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1859\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m ArgumentError:\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/argparse.py:2070\u001b[0m, in \u001b[0;36mArgumentParser._parse_known_args\u001b[0;34m(self, arg_strings, namespace)\u001b[0m\n\u001b[1;32m 2069\u001b[0m \u001b[38;5;66;03m# consume any positionals following the last Optional\u001b[39;00m\n\u001b[0;32m-> 2070\u001b[0m stop_index \u001b[38;5;241m=\u001b[39m \u001b[43mconsume_positionals\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstart_index\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2072\u001b[0m \u001b[38;5;66;03m# if we didn't consume all the argument strings, there were extras\u001b[39;00m\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/argparse.py:2026\u001b[0m, in \u001b[0;36mArgumentParser._parse_known_args.<locals>.consume_positionals\u001b[0;34m(start_index)\u001b[0m\n\u001b[1;32m 2025\u001b[0m start_index \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m arg_count\n\u001b[0;32m-> 2026\u001b[0m \u001b[43mtake_action\u001b[49m\u001b[43m(\u001b[49m\u001b[43maction\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43margs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2028\u001b[0m \u001b[38;5;66;03m# slice off the Positionals that we just parsed and return the\u001b[39;00m\n\u001b[1;32m 2029\u001b[0m \u001b[38;5;66;03m# index at which the Positionals' string args stopped\u001b[39;00m\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/argparse.py:1919\u001b[0m, in \u001b[0;36mArgumentParser._parse_known_args.<locals>.take_action\u001b[0;34m(action, argument_strings, option_string)\u001b[0m\n\u001b[1;32m 1918\u001b[0m seen_actions\u001b[38;5;241m.\u001b[39madd(action)\n\u001b[0;32m-> 1919\u001b[0m argument_values \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get_values\u001b[49m\u001b[43m(\u001b[49m\u001b[43maction\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43margument_strings\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1921\u001b[0m \u001b[38;5;66;03m# error if this argument is not allowed with other previously\u001b[39;00m\n\u001b[1;32m 1922\u001b[0m \u001b[38;5;66;03m# seen arguments, assuming that actions that use the default\u001b[39;00m\n\u001b[1;32m 1923\u001b[0m \u001b[38;5;66;03m# value don't really count as \"present\"\u001b[39;00m\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/argparse.py:2450\u001b[0m, in \u001b[0;36mArgumentParser._get_values\u001b[0;34m(self, action, arg_strings)\u001b[0m\n\u001b[1;32m 2449\u001b[0m arg_string, \u001b[38;5;241m=\u001b[39m arg_strings\n\u001b[0;32m-> 2450\u001b[0m value \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get_value\u001b[49m\u001b[43m(\u001b[49m\u001b[43maction\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43marg_string\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2451\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_check_value(action, value)\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/argparse.py:2496\u001b[0m, in \u001b[0;36mArgumentParser._get_value\u001b[0;34m(self, action, arg_string)\u001b[0m\n\u001b[1;32m 2495\u001b[0m msg \u001b[38;5;241m=\u001b[39m _(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124minvalid \u001b[39m\u001b[38;5;132;01m%(type)s\u001b[39;00m\u001b[38;5;124m value: \u001b[39m\u001b[38;5;132;01m%(value)r\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m-> 2496\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m ArgumentError(action, msg \u001b[38;5;241m%\u001b[39m args)\n\u001b[1;32m 2498\u001b[0m \u001b[38;5;66;03m# return the converted value\u001b[39;00m\n",
"\u001b[0;31mArgumentError\u001b[0m: argument a: invalid int value: '/Users/nacho/Library/Jupyter/runtime/kernel-87e18ef9-d8b7-4e44-9355-73c705ac0d99.json'",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mSystemExit\u001b[0m Traceback (most recent call last)",
" \u001b[0;31m[... skipping hidden 1 frame]\u001b[0m\n",
"Input \u001b[0;32mIn [8]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mscript3\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m pipeline\n\u001b[0;32m----> 2\u001b[0m \u001b[43mpipeline\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m4\u001b[39;49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/fastcore/script.py:106\u001b[0m, in \u001b[0;36mcall_parse.<locals>._f\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 105\u001b[0m mod \u001b[38;5;241m=\u001b[39m inspect\u001b[38;5;241m.\u001b[39mgetmodule(inspect\u001b[38;5;241m.\u001b[39mcurrentframe()\u001b[38;5;241m.\u001b[39mf_back)\n\u001b[0;32m--> 106\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m mod: \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 107\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m SCRIPT_INFO\u001b[38;5;241m.\u001b[39mfunc \u001b[38;5;129;01mand\u001b[39;00m mod\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\u001b[38;5;241m==\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m__main__\u001b[39m\u001b[38;5;124m\"\u001b[39m: SCRIPT_INFO\u001b[38;5;241m.\u001b[39mfunc \u001b[38;5;241m=\u001b[39m func\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\n",
"File \u001b[0;32m~/notebooks/projects/M5_accuracy/script3.py:7\u001b[0m, in \u001b[0;36mpipeline\u001b[0;34m(a, b, d)\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[38;5;129m@call_parse\u001b[39m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpipeline\u001b[39m(a, b, d):\n\u001b[0;32m----> 7\u001b[0m c \u001b[38;5;241m=\u001b[39m \u001b[43mfunc1\u001b[49m\u001b[43m(\u001b[49m\u001b[43ma\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mb\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 8\u001b[0m e \u001b[38;5;241m=\u001b[39m func2(c, d)\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/fastcore/script.py:110\u001b[0m, in \u001b[0;36mcall_parse.<locals>._f\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 109\u001b[0m p \u001b[38;5;241m=\u001b[39m anno_parser(func)\n\u001b[0;32m--> 110\u001b[0m args \u001b[38;5;241m=\u001b[39m \u001b[43mp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mparse_args\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__dict__\u001b[39m\n\u001b[1;32m 111\u001b[0m xtra \u001b[38;5;241m=\u001b[39m otherwise(args\u001b[38;5;241m.\u001b[39mpop(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mxtra\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m'\u001b[39m), eq(\u001b[38;5;241m1\u001b[39m), p\u001b[38;5;241m.\u001b[39mprog)\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/argparse.py:1825\u001b[0m, in \u001b[0;36mArgumentParser.parse_args\u001b[0;34m(self, args, namespace)\u001b[0m\n\u001b[1;32m 1824\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mparse_args\u001b[39m(\u001b[38;5;28mself\u001b[39m, args\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m, namespace\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[0;32m-> 1825\u001b[0m args, argv \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mparse_known_args\u001b[49m\u001b[43m(\u001b[49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnamespace\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1826\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m argv:\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/argparse.py:1861\u001b[0m, in \u001b[0;36mArgumentParser.parse_known_args\u001b[0;34m(self, args, namespace)\u001b[0m\n\u001b[1;32m 1860\u001b[0m err \u001b[38;5;241m=\u001b[39m _sys\u001b[38;5;241m.\u001b[39mexc_info()[\u001b[38;5;241m1\u001b[39m]\n\u001b[0;32m-> 1861\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43merror\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43merr\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1862\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/argparse.py:2582\u001b[0m, in \u001b[0;36mArgumentParser.error\u001b[0;34m(self, message)\u001b[0m\n\u001b[1;32m 2581\u001b[0m args \u001b[38;5;241m=\u001b[39m {\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mprog\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprog, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmessage\u001b[39m\u001b[38;5;124m'\u001b[39m: message}\n\u001b[0;32m-> 2582\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexit\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;132;43;01m%(prog)s\u001b[39;49;00m\u001b[38;5;124;43m: error: \u001b[39;49m\u001b[38;5;132;43;01m%(message)s\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m%\u001b[39;49m\u001b[43m \u001b[49m\u001b[43margs\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/argparse.py:2569\u001b[0m, in \u001b[0;36mArgumentParser.exit\u001b[0;34m(self, status, message)\u001b[0m\n\u001b[1;32m 2568\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_print_message(message, _sys\u001b[38;5;241m.\u001b[39mstderr)\n\u001b[0;32m-> 2569\u001b[0m \u001b[43m_sys\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexit\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstatus\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mSystemExit\u001b[0m: 2",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mAssertionError\u001b[0m Traceback (most recent call last)",
" \u001b[0;31m[... skipping hidden 1 frame]\u001b[0m\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/IPython/core/interactiveshell.py:1983\u001b[0m, in \u001b[0;36mInteractiveShell.showtraceback\u001b[0;34m(self, exc_tuple, filename, tb_offset, exception_only, running_compiled_code)\u001b[0m\n\u001b[1;32m 1980\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m exception_only:\n\u001b[1;32m 1981\u001b[0m stb \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mAn exception has occurred, use \u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124mtb to see \u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 1982\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mthe full traceback.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m]\n\u001b[0;32m-> 1983\u001b[0m stb\u001b[38;5;241m.\u001b[39mextend(\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mInteractiveTB\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_exception_only\u001b[49m\u001b[43m(\u001b[49m\u001b[43metype\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1984\u001b[0m \u001b[43m \u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m)\u001b[49m)\n\u001b[1;32m 1985\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1986\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m 1987\u001b[0m \u001b[38;5;66;03m# Exception classes can customise their traceback - we\u001b[39;00m\n\u001b[1;32m 1988\u001b[0m \u001b[38;5;66;03m# use this in IPython.parallel for exceptions occurring\u001b[39;00m\n\u001b[1;32m 1989\u001b[0m \u001b[38;5;66;03m# in the engines. This should return a list of strings.\u001b[39;00m\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/IPython/core/ultratb.py:585\u001b[0m, in \u001b[0;36mListTB.get_exception_only\u001b[0;34m(self, etype, value)\u001b[0m\n\u001b[1;32m 577\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mget_exception_only\u001b[39m(\u001b[38;5;28mself\u001b[39m, etype, value):\n\u001b[1;32m 578\u001b[0m \u001b[38;5;124;03m\"\"\"Only print the exception type and message, without a traceback.\u001b[39;00m\n\u001b[1;32m 579\u001b[0m \n\u001b[1;32m 580\u001b[0m \u001b[38;5;124;03m Parameters\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 583\u001b[0m \u001b[38;5;124;03m value : exception value\u001b[39;00m\n\u001b[1;32m 584\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 585\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mListTB\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstructured_traceback\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43metype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/IPython/core/ultratb.py:443\u001b[0m, in \u001b[0;36mListTB.structured_traceback\u001b[0;34m(self, etype, evalue, etb, tb_offset, context)\u001b[0m\n\u001b[1;32m 440\u001b[0m chained_exc_ids\u001b[38;5;241m.\u001b[39madd(\u001b[38;5;28mid\u001b[39m(exception[\u001b[38;5;241m1\u001b[39m]))\n\u001b[1;32m 441\u001b[0m chained_exceptions_tb_offset \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n\u001b[1;32m 442\u001b[0m out_list \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 443\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstructured_traceback\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 444\u001b[0m \u001b[43m \u001b[49m\u001b[43metype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mevalue\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m(\u001b[49m\u001b[43metb\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mchained_exc_ids\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 445\u001b[0m \u001b[43m \u001b[49m\u001b[43mchained_exceptions_tb_offset\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcontext\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 446\u001b[0m \u001b[38;5;241m+\u001b[39m chained_exception_message\n\u001b[1;32m 447\u001b[0m \u001b[38;5;241m+\u001b[39m out_list)\n\u001b[1;32m 449\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m out_list\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/IPython/core/ultratb.py:1118\u001b[0m, in \u001b[0;36mAutoFormattedTB.structured_traceback\u001b[0;34m(self, etype, value, tb, tb_offset, number_of_lines_of_context)\u001b[0m\n\u001b[1;32m 1116\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1117\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mtb \u001b[38;5;241m=\u001b[39m tb\n\u001b[0;32m-> 1118\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mFormattedTB\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstructured_traceback\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1119\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43metype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtb\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtb_offset\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnumber_of_lines_of_context\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/IPython/core/ultratb.py:1012\u001b[0m, in \u001b[0;36mFormattedTB.structured_traceback\u001b[0;34m(self, etype, value, tb, tb_offset, number_of_lines_of_context)\u001b[0m\n\u001b[1;32m 1009\u001b[0m mode \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmode\n\u001b[1;32m 1010\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m mode \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mverbose_modes:\n\u001b[1;32m 1011\u001b[0m \u001b[38;5;66;03m# Verbose modes need a full traceback\u001b[39;00m\n\u001b[0;32m-> 1012\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mVerboseTB\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstructured_traceback\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1013\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43metype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtb\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtb_offset\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnumber_of_lines_of_context\u001b[49m\n\u001b[1;32m 1014\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1015\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m mode \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mMinimal\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m 1016\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m ListTB\u001b[38;5;241m.\u001b[39mget_exception_only(\u001b[38;5;28mself\u001b[39m, etype, value)\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/IPython/core/ultratb.py:865\u001b[0m, in \u001b[0;36mVerboseTB.structured_traceback\u001b[0;34m(self, etype, evalue, etb, tb_offset, number_of_lines_of_context)\u001b[0m\n\u001b[1;32m 856\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mstructured_traceback\u001b[39m(\n\u001b[1;32m 857\u001b[0m \u001b[38;5;28mself\u001b[39m,\n\u001b[1;32m 858\u001b[0m etype: \u001b[38;5;28mtype\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 862\u001b[0m number_of_lines_of_context: \u001b[38;5;28mint\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m5\u001b[39m,\n\u001b[1;32m 863\u001b[0m ):\n\u001b[1;32m 864\u001b[0m \u001b[38;5;124;03m\"\"\"Return a nice text document describing the traceback.\"\"\"\u001b[39;00m\n\u001b[0;32m--> 865\u001b[0m formatted_exception \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mformat_exception_as_a_whole\u001b[49m\u001b[43m(\u001b[49m\u001b[43metype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mevalue\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43metb\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnumber_of_lines_of_context\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 866\u001b[0m \u001b[43m \u001b[49m\u001b[43mtb_offset\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 868\u001b[0m colors \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mColors \u001b[38;5;66;03m# just a shorthand + quicker name lookup\u001b[39;00m\n\u001b[1;32m 869\u001b[0m colorsnormal \u001b[38;5;241m=\u001b[39m colors\u001b[38;5;241m.\u001b[39mNormal \u001b[38;5;66;03m# used a lot\u001b[39;00m\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/IPython/core/ultratb.py:799\u001b[0m, in \u001b[0;36mVerboseTB.format_exception_as_a_whole\u001b[0;34m(self, etype, evalue, etb, number_of_lines_of_context, tb_offset)\u001b[0m\n\u001b[1;32m 796\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(tb_offset, \u001b[38;5;28mint\u001b[39m)\n\u001b[1;32m 797\u001b[0m head \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprepare_header(etype, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlong_header)\n\u001b[1;32m 798\u001b[0m records \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m--> 799\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_records\u001b[49m\u001b[43m(\u001b[49m\u001b[43metb\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mnumber_of_lines_of_context\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtb_offset\u001b[49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mif\u001b[39;00m etb \u001b[38;5;28;01melse\u001b[39;00m []\n\u001b[1;32m 800\u001b[0m )\n\u001b[1;32m 802\u001b[0m frames \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m 803\u001b[0m skipped \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/IPython/core/ultratb.py:854\u001b[0m, in \u001b[0;36mVerboseTB.get_records\u001b[0;34m(self, etb, number_of_lines_of_context, tb_offset)\u001b[0m\n\u001b[1;32m 848\u001b[0m formatter \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 849\u001b[0m options \u001b[38;5;241m=\u001b[39m stack_data\u001b[38;5;241m.\u001b[39mOptions(\n\u001b[1;32m 850\u001b[0m before\u001b[38;5;241m=\u001b[39mbefore,\n\u001b[1;32m 851\u001b[0m after\u001b[38;5;241m=\u001b[39mafter,\n\u001b[1;32m 852\u001b[0m pygments_formatter\u001b[38;5;241m=\u001b[39mformatter,\n\u001b[1;32m 853\u001b[0m )\n\u001b[0;32m--> 854\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mlist\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mstack_data\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mFrameInfo\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mstack_data\u001b[49m\u001b[43m(\u001b[49m\u001b[43metb\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m[tb_offset:]\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/stack_data/core.py:546\u001b[0m, in \u001b[0;36mFrameInfo.stack_data\u001b[0;34m(cls, frame_or_tb, options, collapse_repeated_frames)\u001b[0m\n\u001b[1;32m 530\u001b[0m \u001b[38;5;129m@classmethod\u001b[39m\n\u001b[1;32m 531\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mstack_data\u001b[39m(\n\u001b[1;32m 532\u001b[0m \u001b[38;5;28mcls\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 536\u001b[0m collapse_repeated_frames: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m 537\u001b[0m ) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m Iterator[Union[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mFrameInfo\u001b[39m\u001b[38;5;124m'\u001b[39m, RepeatedFrames]]:\n\u001b[1;32m 538\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 539\u001b[0m \u001b[38;5;124;03m An iterator of FrameInfo and RepeatedFrames objects representing\u001b[39;00m\n\u001b[1;32m 540\u001b[0m \u001b[38;5;124;03m a full traceback or stack. Similar consecutive frames are collapsed into RepeatedFrames\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 544\u001b[0m \u001b[38;5;124;03m and optionally an Options object to configure.\u001b[39;00m\n\u001b[1;32m 545\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 546\u001b[0m stack \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mlist\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43miter_stack\u001b[49m\u001b[43m(\u001b[49m\u001b[43mframe_or_tb\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 548\u001b[0m \u001b[38;5;66;03m# Reverse the stack from a frame so that it's in the same order\u001b[39;00m\n\u001b[1;32m 549\u001b[0m \u001b[38;5;66;03m# as the order from a traceback, which is the order of a printed\u001b[39;00m\n\u001b[1;32m 550\u001b[0m \u001b[38;5;66;03m# traceback when read top to bottom (most recent call last)\u001b[39;00m\n\u001b[1;32m 551\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_frame(frame_or_tb):\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/stack_data/utils.py:98\u001b[0m, in \u001b[0;36miter_stack\u001b[0;34m(frame_or_tb)\u001b[0m\n\u001b[1;32m 96\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m frame_or_tb:\n\u001b[1;32m 97\u001b[0m \u001b[38;5;28;01myield\u001b[39;00m frame_or_tb\n\u001b[0;32m---> 98\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mis_frame\u001b[49m\u001b[43m(\u001b[49m\u001b[43mframe_or_tb\u001b[49m\u001b[43m)\u001b[49m:\n\u001b[1;32m 99\u001b[0m frame_or_tb \u001b[38;5;241m=\u001b[39m frame_or_tb\u001b[38;5;241m.\u001b[39mf_back\n\u001b[1;32m 100\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/stack_data/utils.py:91\u001b[0m, in \u001b[0;36mis_frame\u001b[0;34m(frame_or_tb)\u001b[0m\n\u001b[1;32m 90\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mis_frame\u001b[39m(frame_or_tb: Union[FrameType, TracebackType]) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28mbool\u001b[39m:\n\u001b[0;32m---> 91\u001b[0m \u001b[43massert_\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43misinstance\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mframe_or_tb\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m(\u001b[49m\u001b[43mtypes\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mFrameType\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtypes\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mTracebackType\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 92\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(frame_or_tb, (types\u001b[38;5;241m.\u001b[39mFrameType,))\n",
"File \u001b[0;32m~/opt/anaconda3/envs/tsai_pro_env/lib/python3.10/site-packages/stack_data/utils.py:172\u001b[0m, in \u001b[0;36massert_\u001b[0;34m(condition, error)\u001b[0m\n\u001b[1;32m 170\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(error, \u001b[38;5;28mstr\u001b[39m):\n\u001b[1;32m 171\u001b[0m error \u001b[38;5;241m=\u001b[39m \u001b[38;5;167;01mAssertionError\u001b[39;00m(error)\n\u001b[0;32m--> 172\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m error\n",
"\u001b[0;31mAssertionError\u001b[0m: "
]
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "# Approach 3 does work"
},
{
"metadata": {},
"cell_type": "markdown",
"source": "This is a solution proposed by @jokellum in the fastai discord channel ([link](https://discord.com/channels/689892369998676007/737149430498721842/988393534375735376))"
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:53:58.300588Z",
"end_time": "2022-06-20T10:53:58.327087Z"
},
"trusted": true
},
"cell_type": "code",
"source": "%%file script1b.py\nfrom fastcore.script import *\n\n@call_parse\ndef func1(\n a:int, # param a\n b:int, # param b\n): return a + b",
"execution_count": 9,
"outputs": [
{
"output_type": "stream",
"text": "Writing script1b.py\n",
"name": "stdout"
}
]
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:54:01.232995Z",
"end_time": "2022-06-20T10:54:01.244868Z"
},
"trusted": true
},
"cell_type": "code",
"source": "%%file script2b.py\nfrom fastcore.script import *\n\n@call_parse\ndef func2(\n c:int, # param c\n d:int, # param d\n): return c + d",
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"text": "Writing script2b.py\n",
"name": "stdout"
}
]
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:54:34.080997Z",
"end_time": "2022-06-20T10:54:34.094044Z"
},
"trusted": true
},
"cell_type": "code",
"source": "%%file script3c.py\nfrom script1b import func1 # this function uses @call_parse\nfrom script2b import func2 # this function uses @call_parse\nfrom fastcore.script import *\n\n@call_parse\ndef pipeline(a, b, d):\n c = func1.__wrapped__(a, b)\n e = func2.__wrapped__(c, d)\n return e",
"execution_count": 12,
"outputs": [
{
"output_type": "stream",
"text": "Writing script3c.py\n",
"name": "stdout"
}
]
},
{
"metadata": {
"ExecuteTime": {
"start_time": "2022-06-20T10:54:35.726237Z",
"end_time": "2022-06-20T10:54:35.782221Z"
},
"trusted": true
},
"cell_type": "code",
"source": "from script3c import pipeline\npipeline(2, 3, 4)",
"execution_count": 13,
"outputs": [
{
"output_type": "execute_result",
"execution_count": 13,
"data": {
"text/plain": "9"
},
"metadata": {}
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3 (ipykernel)",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.10.4",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"toc": {
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"base_numbering": 1,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"gist": {
"id": "7d4d2e5152b7537af4b647274b01b3ac",
"data": {
"description": "Data_pipeline.ipynb",
"public": true
}
},
"_draft": {
"nbviewer_url": "https://gist.github.com/7d4d2e5152b7537af4b647274b01b3ac"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment