Skip to content

Instantly share code, notes, and snippets.

@rgbkrk
Created November 14, 2020 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgbkrk/5375e2da4552c36e805065b4cfe1afce to your computer and use it in GitHub Desktop.
Save rgbkrk/5375e2da4552c36e805065b4cfe1afce to your computer and use it in GitHub Desktop.
comparing notebooks
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import JSON\n",
"import json\n",
"\n",
"import difflib\n",
"import vdom\n",
"from vdom import h1, h2, h3, p, pre, b, div"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def extract(data):\n",
" return data['cells'][3]['outputs'][1]['data']"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"with open(\"./KQL-bug.ipynb\") as kb:\n",
" kql_bug_data = json.load(kb)\n",
" \n",
"with open(\"./KQL-papermill.ipynb\") as kp:\n",
" kql_papermill_data = json.load(kp)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"kql_bug_cell_3_outputs = kql_bug_data['cells'][3]['outputs']\n",
"kql_pap_cell_3_outputs = kql_papermill_data['cells'][3]['outputs']"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(kql_bug_cell_3_outputs) == len(kql_pap_cell_3_outputs)"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
{
"attributes": {},
"children": [
"Running analysis on cell with code"
],
"tagName": "p"
},
{
"attributes": {},
"children": [
"%kql StormEvents | take 10\n"
],
"tagName": "pre"
}
],
"tagName": "div"
},
"text/html": [
"<div><p>Running analysis on cell with code</p><pre>%kql StormEvents | take 10\n",
"</pre></div>"
],
"text/plain": [
"<div><p>Running analysis on cell with code</p><pre>%kql StormEvents | take 10\n",
"</pre></div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
"Output 0: same"
],
"tagName": "h2"
},
"text/html": [
"<h2>Output 0: same</h2>"
],
"text/plain": [
"<h2>Output 0: same</h2>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
"Output 1: same"
],
"tagName": "h2"
},
"text/html": [
"<h2>Output 1: same</h2>"
],
"text/plain": [
"<h2>Output 1: same</h2>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
"Output 2: NOT the same"
],
"tagName": "h2"
},
"text/html": [
"<h2>Output 2: NOT the same</h2>"
],
"text/plain": [
"<h2>Output 2: NOT the same</h2>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
"Comparing keys"
],
"tagName": "h3"
},
"text/html": [
"<h3>Comparing keys</h3>"
],
"text/plain": [
"<h3>Comparing keys</h3>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
{
"attributes": {},
"children": [
"data"
],
"tagName": "b"
},
" - ",
{
"attributes": {
"style": {
"font-family": "monospace"
}
},
"children": [
"False"
],
"tagName": "span"
}
],
"tagName": "div"
},
"text/html": [
"<div><b>data</b> - <span style=\"font-family: monospace\">False</span></div>"
],
"text/plain": [
"<div><b>data</b> - <span style=\"font-family: monospace\">False</span></div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
{
"attributes": {},
"children": [
"metadata"
],
"tagName": "b"
},
" - ",
{
"attributes": {
"style": {
"font-family": "monospace"
}
},
"children": [
"True"
],
"tagName": "span"
}
],
"tagName": "div"
},
"text/html": [
"<div><b>metadata</b> - <span style=\"font-family: monospace\">True</span></div>"
],
"text/plain": [
"<div><b>metadata</b> - <span style=\"font-family: monospace\">True</span></div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
{
"attributes": {},
"children": [
"output_type"
],
"tagName": "b"
},
" - ",
{
"attributes": {
"style": {
"font-family": "monospace"
}
},
"children": [
"True"
],
"tagName": "span"
}
],
"tagName": "div"
},
"text/html": [
"<div><b>output_type</b> - <span style=\"font-family: monospace\">True</span></div>"
],
"text/plain": [
"<div><b>output_type</b> - <span style=\"font-family: monospace\">True</span></div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
"Output 3: NOT the same"
],
"tagName": "h2"
},
"text/html": [
"<h2>Output 3: NOT the same</h2>"
],
"text/plain": [
"<h2>Output 3: NOT the same</h2>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
"Comparing keys"
],
"tagName": "h3"
},
"text/html": [
"<h3>Comparing keys</h3>"
],
"text/plain": [
"<h3>Comparing keys</h3>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
{
"attributes": {},
"children": [
"data"
],
"tagName": "b"
},
" - ",
{
"attributes": {
"style": {
"font-family": "monospace"
}
},
"children": [
"True"
],
"tagName": "span"
}
],
"tagName": "div"
},
"text/html": [
"<div><b>data</b> - <span style=\"font-family: monospace\">True</span></div>"
],
"text/plain": [
"<div><b>data</b> - <span style=\"font-family: monospace\">True</span></div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
{
"attributes": {},
"children": [
"execution_count"
],
"tagName": "b"
},
" - ",
{
"attributes": {
"style": {
"font-family": "monospace"
}
},
"children": [
"False"
],
"tagName": "span"
}
],
"tagName": "div"
},
"text/html": [
"<div><b>execution_count</b> - <span style=\"font-family: monospace\">False</span></div>"
],
"text/plain": [
"<div><b>execution_count</b> - <span style=\"font-family: monospace\">False</span></div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
{
"attributes": {},
"children": [
"metadata"
],
"tagName": "b"
},
" - ",
{
"attributes": {
"style": {
"font-family": "monospace"
}
},
"children": [
"True"
],
"tagName": "span"
}
],
"tagName": "div"
},
"text/html": [
"<div><b>metadata</b> - <span style=\"font-family: monospace\">True</span></div>"
],
"text/plain": [
"<div><b>metadata</b> - <span style=\"font-family: monospace\">True</span></div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
{
"attributes": {},
"children": [
"output_type"
],
"tagName": "b"
},
" - ",
{
"attributes": {
"style": {
"font-family": "monospace"
}
},
"children": [
"True"
],
"tagName": "span"
}
],
"tagName": "div"
},
"text/html": [
"<div><b>output_type</b> - <span style=\"font-family: monospace\">True</span></div>"
],
"text/plain": [
"<div><b>output_type</b> - <span style=\"font-family: monospace\">True</span></div>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(\n",
" div(\n",
" p(\"Running analysis on cell with code\"),\n",
" pre(kql_bug_data['cells'][3]['source'])\n",
" )\n",
")\n",
"\n",
"for (idx, _) in enumerate(kql_bug_cell_3_outputs):\n",
" output_b = kql_bug_cell_3_outputs[idx]\n",
" output_p = kql_pap_cell_3_outputs[idx]\n",
" \n",
" outputs_are_same = output_b == output_p\n",
" if outputs_are_same:\n",
" display(h2(f\"Output {idx}: same\"))\n",
" else:\n",
" display(h2(f\"Output {idx}: NOT the same\"))\n",
" \n",
" display(h3(\"Comparing keys\"))\n",
" for k in output_b:\n",
" display(div(b(k), \" - \", vdom.span(f\"{output_b[k] == output_p[k]}\", style={\"font-family\": \"monospace\"})))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since output 3's only difference is the execution count, let's take a look at output 2 which has a difference in the data."
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [],
"source": [
"bo_2 = kql_bug_cell_3_outputs[2]\n",
"po_2 = kql_pap_cell_3_outputs[2]"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
{
"attributes": {},
"children": [
"text/html"
],
"tagName": "h3"
},
{
"attributes": {},
"children": [
" <html>\n",
" <head>\n",
" \n",
" \n",
" </head>\n",
" <body>\n",
"- <div><p style='padding: 10px; color: #3a87ad; background-color: #d9edf7; border-color: #bce9f1'>Done&nbsp;(00:00.838):&nbsp;10&nbsp;records</p></div>\n",
"? ^^\n",
"+ <div><p style='padding: 10px; color: #3a87ad; background-color: #d9edf7; border-color: #bce9f1'>Done&nbsp;(00:00.278):&nbsp;10&nbsp;records</p></div>\n",
"? ^^\n",
" </body>\n",
" </html>"
],
"tagName": "pre"
}
],
"tagName": "div"
},
"text/html": [
"<div><h3>text/html</h3><pre> &lt;html&gt;\n",
" &lt;head&gt;\n",
" \n",
" \n",
" &lt;/head&gt;\n",
" &lt;body&gt;\n",
"- &lt;div&gt;&lt;p style=&#x27;padding: 10px; color: #3a87ad; background-color: #d9edf7; border-color: #bce9f1&#x27;&gt;Done&amp;nbsp;(00:00.838):&amp;nbsp;10&amp;nbsp;records&lt;/p&gt;&lt;/div&gt;\n",
"? ^^\n",
"+ &lt;div&gt;&lt;p style=&#x27;padding: 10px; color: #3a87ad; background-color: #d9edf7; border-color: #bce9f1&#x27;&gt;Done&amp;nbsp;(00:00.278):&amp;nbsp;10&amp;nbsp;records&lt;/p&gt;&lt;/div&gt;\n",
"? ^^\n",
" &lt;/body&gt;\n",
" &lt;/html&gt;</pre></div>"
],
"text/plain": [
"<div><h3>text/html</h3><pre> &lt;html&gt;\n",
" &lt;head&gt;\n",
" \n",
" \n",
" &lt;/head&gt;\n",
" &lt;body&gt;\n",
"- &lt;div&gt;&lt;p style=&#x27;padding: 10px; color: #3a87ad; background-color: #d9edf7; border-color: #bce9f1&#x27;&gt;Done&amp;nbsp;(00:00.838):&amp;nbsp;10&amp;nbsp;records&lt;/p&gt;&lt;/div&gt;\n",
"? ^^\n",
"+ &lt;div&gt;&lt;p style=&#x27;padding: 10px; color: #3a87ad; background-color: #d9edf7; border-color: #bce9f1&#x27;&gt;Done&amp;nbsp;(00:00.278):&amp;nbsp;10&amp;nbsp;records&lt;/p&gt;&lt;/div&gt;\n",
"? ^^\n",
" &lt;/body&gt;\n",
" &lt;/html&gt;</pre></div>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vdom.v1+json": {
"attributes": {},
"children": [
{
"attributes": {},
"children": [
"text/plain"
],
"tagName": "h3"
},
{
"attributes": {},
"children": [
" <IPython.core.display.HTML object>"
],
"tagName": "pre"
}
],
"tagName": "div"
},
"text/html": [
"<div><h3>text/plain</h3><pre> &lt;IPython.core.display.HTML object&gt;</pre></div>"
],
"text/plain": [
"<div><h3>text/plain</h3><pre> &lt;IPython.core.display.HTML object&gt;</pre></div>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"for k in bo_2['data']:\n",
" display(\n",
" div(\n",
" h3(k),\n",
" pre(list(difflib.ndiff(bo_2['data'][k], po_2['data'][k])))\n",
" )\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment