aboutsummaryrefslogtreecommitdiff
path: root/demo/notebooks/bad-bom.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'demo/notebooks/bad-bom.ipynb')
-rw-r--r--demo/notebooks/bad-bom.ipynb437
1 files changed, 437 insertions, 0 deletions
diff --git a/demo/notebooks/bad-bom.ipynb b/demo/notebooks/bad-bom.ipynb
new file mode 100644
index 0000000..e84de79
--- /dev/null
+++ b/demo/notebooks/bad-bom.ipynb
@@ -0,0 +1,437 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Notebook configuration"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 248,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "The autoreload extension is already loaded. To reload it, use:\n",
+ " %reload_ext autoreload\n"
+ ]
+ },
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "[autoreload of ee failed: Traceback (most recent call last):\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/IPython/extensions/autoreload.py\", line 246, in check\n",
+ " superreload(m, reload, self.old_objects)\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/IPython/extensions/autoreload.py\", line 369, in superreload\n",
+ " module = reload(module)\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/imp.py\", line 315, in reload\n",
+ " return importlib.reload(module)\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/importlib/__init__.py\", line 166, in reload\n",
+ " _bootstrap._exec(spec, module)\n",
+ " File \"<frozen importlib._bootstrap>\", line 626, in _exec\n",
+ " File \"<frozen importlib._bootstrap_external>\", line 697, in exec_module\n",
+ " File \"<frozen importlib._bootstrap>\", line 222, in _call_with_frames_removed\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/src/ee/__init__.py\", line 43, in <module>\n",
+ " EeVal.r = re.compile(\"([0-9]+)( *)([\" + join(EeVal.exponents.keys()) + \"])\")\n",
+ "NameError: name 'join' is not defined\n",
+ "]\n",
+ "[autoreload of ee failed: Traceback (most recent call last):\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/IPython/extensions/autoreload.py\", line 246, in check\n",
+ " superreload(m, reload, self.old_objects)\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/IPython/extensions/autoreload.py\", line 369, in superreload\n",
+ " module = reload(module)\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/imp.py\", line 315, in reload\n",
+ " return importlib.reload(module)\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/importlib/__init__.py\", line 166, in reload\n",
+ " _bootstrap._exec(spec, module)\n",
+ " File \"<frozen importlib._bootstrap>\", line 626, in _exec\n",
+ " File \"<frozen importlib._bootstrap_external>\", line 697, in exec_module\n",
+ " File \"<frozen importlib._bootstrap>\", line 222, in _call_with_frames_removed\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/src/ee/__init__.py\", line 43, in <module>\n",
+ " EeVal.r = re.compile(\"([0-9]+)( *)([\" + join(EeVal.exponents.keys()) + \"])\")\n",
+ "NameError: name 'join' is not defined\n",
+ "]\n"
+ ]
+ },
+ {
+ "ename": "NameError",
+ "evalue": "name 'EeVal' is not defined",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m<ipython-input-248-a1070d7b586a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mee\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkicad\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbom\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mee\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkicad\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mio\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mread_bom\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 11\u001b[0;31m \u001b[0mEeVal\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mr\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m: name 'EeVal' is not defined"
+ ]
+ }
+ ],
+ "source": [
+ "%load_ext autoreload\n",
+ "%autoreload 2\n",
+ "\n",
+ "%aimport ee.kicad.bom\n",
+ "%aimport ee.kicad.bom.io\n",
+ "\n",
+ "import ee\n",
+ "from ee.formatting import *\n",
+ "from ee.kicad.bom import *\n",
+ "from ee.kicad.bom.io import read_bom\n",
+ "EeVal.r"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Load the BOM"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 239,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "<div>\n",
+ "<style>\n",
+ " .dataframe thead tr:only-child th {\n",
+ " text-align: right;\n",
+ " }\n",
+ "\n",
+ " .dataframe thead th {\n",
+ " text-align: left;\n",
+ " }\n",
+ "\n",
+ " .dataframe tbody tr th {\n",
+ " vertical-align: top;\n",
+ " }\n",
+ "</style>\n",
+ "<table border=\"1\" class=\"dataframe\">\n",
+ " <thead>\n",
+ " <tr style=\"text-align: right;\">\n",
+ " <th></th>\n",
+ " <th>digikey</th>\n",
+ " <th>mpn</th>\n",
+ " <th>ref</th>\n",
+ " <th>value</th>\n",
+ " </tr>\n",
+ " </thead>\n",
+ " <tbody>\n",
+ " <tr>\n",
+ " <th>R1</th>\n",
+ " <td>311-1.00KFRTR-ND</td>\n",
+ " <td>RC1206FR-071KL</td>\n",
+ " <td>R1</td>\n",
+ " <td>10k</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>C4</th>\n",
+ " <td>None</td>\n",
+ " <td>None</td>\n",
+ " <td>C4</td>\n",
+ " <td>1uF</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>R2</th>\n",
+ " <td>None</td>\n",
+ " <td>None</td>\n",
+ " <td>R2</td>\n",
+ " <td>10k</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>C3</th>\n",
+ " <td>None</td>\n",
+ " <td>None</td>\n",
+ " <td>C3</td>\n",
+ " <td>100n</td>\n",
+ " </tr>\n",
+ " </tbody>\n",
+ "</table>\n",
+ "</div>"
+ ],
+ "text/plain": [
+ " digikey mpn ref value\n",
+ "R1 311-1.00KFRTR-ND RC1206FR-071KL R1 10k\n",
+ "C4 None None C4 1uF\n",
+ "R2 None None R2 10k\n",
+ "C3 None None C3 100n"
+ ]
+ },
+ "execution_count": 239,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "import os\n",
+ "import os.path\n",
+ "import pandas\n",
+ "\n",
+ "bom = read_bom(\"../kicad/bad-bom.xml\").to_pandas()\n",
+ "bom"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 244,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "[autoreload of ee failed: Traceback (most recent call last):\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/IPython/extensions/autoreload.py\", line 246, in check\n",
+ " superreload(m, reload, self.old_objects)\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/IPython/extensions/autoreload.py\", line 369, in superreload\n",
+ " module = reload(module)\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/imp.py\", line 315, in reload\n",
+ " return importlib.reload(module)\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/importlib/__init__.py\", line 166, in reload\n",
+ " _bootstrap._exec(spec, module)\n",
+ " File \"<frozen importlib._bootstrap>\", line 626, in _exec\n",
+ " File \"<frozen importlib._bootstrap_external>\", line 697, in exec_module\n",
+ " File \"<frozen importlib._bootstrap>\", line 222, in _call_with_frames_removed\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/src/ee/__init__.py\", line 42, in <module>\n",
+ " EeVal.r = re.compile(\"([0-9]+)( *)([\" + join(EeVal.exponents.keys()) + \"])\")\n",
+ "NameError: name 're' is not defined\n",
+ "]\n",
+ "[autoreload of ee failed: Traceback (most recent call last):\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/IPython/extensions/autoreload.py\", line 246, in check\n",
+ " superreload(m, reload, self.old_objects)\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/IPython/extensions/autoreload.py\", line 369, in superreload\n",
+ " module = reload(module)\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/imp.py\", line 315, in reload\n",
+ " return importlib.reload(module)\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/importlib/__init__.py\", line 166, in reload\n",
+ " _bootstrap._exec(spec, module)\n",
+ " File \"<frozen importlib._bootstrap>\", line 626, in _exec\n",
+ " File \"<frozen importlib._bootstrap_external>\", line 697, in exec_module\n",
+ " File \"<frozen importlib._bootstrap>\", line 222, in _call_with_frames_removed\n",
+ " File \"/home/trygvis/dev/io.trygvis/2017/07/ee-python/src/ee/__init__.py\", line 42, in <module>\n",
+ " EeVal.r = re.compile(\"([0-9]+)( *)([\" + join(EeVal.exponents.keys()) + \"])\")\n",
+ "NameError: name 're' is not defined\n",
+ "]\n"
+ ]
+ },
+ {
+ "ename": "TypeError",
+ "evalue": "exceptions must derive from BaseException",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m<ipython-input-244-5cbfacf10364>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mbom\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"value\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mee_parse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
+ "\u001b[0;32m~/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/pandas/core/series.py\u001b[0m in \u001b[0;36mapply\u001b[0;34m(self, func, convert_dtype, args, **kwds)\u001b[0m\n\u001b[1;32m 2353\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2354\u001b[0m \u001b[0mvalues\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masobject\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2355\u001b[0;31m \u001b[0mmapped\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmap_infer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mconvert\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mconvert_dtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2356\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2357\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmapped\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmapped\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mSeries\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;32mpandas/_libs/src/inference.pyx\u001b[0m in \u001b[0;36mpandas._libs.lib.map_infer (pandas/_libs/lib.c:66645)\u001b[0;34m()\u001b[0m\n",
+ "\u001b[0;32m~/dev/io.trygvis/2017/07/ee-python/src/ee/formatting/__init__.py\u001b[0m in \u001b[0;36mee_parse\u001b[0;34m(s)\u001b[0m\n\u001b[1;32m 99\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 100\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mee_parse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ms\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 101\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0;34m\"deprecated\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 102\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mdecimal\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mDecimal\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 103\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;31mTypeError\u001b[0m: exceptions must derive from BaseException"
+ ]
+ }
+ ],
+ "source": [
+ "bom[\"value\"].apply(ee_parse)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 229,
+ "metadata": {},
+ "outputs": [
+ {
+ "ename": "KeyError",
+ "evalue": "'Part Number'",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32m<ipython-input-229-4f16cda01558>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mpn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mitem\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mbom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgroupby\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'Part Number'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mg\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_group\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"# {}:\\n{}\\n\\n\"\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpn\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mg\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;32m~/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36mgroupby\u001b[0;34m(self, by, axis, level, as_index, sort, group_keys, squeeze, **kwargs)\u001b[0m\n\u001b[1;32m 4414\u001b[0m return groupby(self, by=by, axis=axis, level=level, as_index=as_index,\n\u001b[1;32m 4415\u001b[0m \u001b[0msort\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msort\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgroup_keys\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mgroup_keys\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msqueeze\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msqueeze\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 4416\u001b[0;31m **kwargs)\n\u001b[0m\u001b[1;32m 4417\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4418\u001b[0m def asfreq(self, freq, method=None, how=None, normalize=False,\n",
+ "\u001b[0;32m~/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/pandas/core/groupby.py\u001b[0m in \u001b[0;36mgroupby\u001b[0;34m(obj, by, **kwds)\u001b[0m\n\u001b[1;32m 1697\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'invalid type: %s'\u001b[0m \u001b[0;34m%\u001b[0m \u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1698\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1699\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mklass\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mby\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1700\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1701\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;32m~/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/pandas/core/groupby.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, **kwargs)\u001b[0m\n\u001b[1;32m 390\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlevel\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 391\u001b[0m \u001b[0msort\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msort\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 392\u001b[0;31m mutated=self.mutated)\n\u001b[0m\u001b[1;32m 393\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 394\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mobj\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mobj\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;32m~/dev/io.trygvis/2017/07/ee-python/env-python3/lib/python3.5/site-packages/pandas/core/groupby.py\u001b[0m in \u001b[0;36m_get_grouper\u001b[0;34m(obj, key, axis, level, sort, mutated)\u001b[0m\n\u001b[1;32m 2688\u001b[0m \u001b[0min_axis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgpr\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgpr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2689\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2690\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgpr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2691\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgpr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mGrouper\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mgpr\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkey\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2692\u001b[0m \u001b[0;31m# Add key to exclusions\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
+ "\u001b[0;31mKeyError\u001b[0m: 'Part Number'"
+ ]
+ }
+ ],
+ "source": [
+ "for pn, item in bom.groupby(['Part Number']):\n",
+ " g = x.get_group(pn)\n",
+ " print(\"# {}:\\n{}\\n\\n\".format(pn, len(g)))\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 325,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "<div>\n",
+ "<style>\n",
+ " .dataframe thead tr:only-child th {\n",
+ " text-align: right;\n",
+ " }\n",
+ "\n",
+ " .dataframe thead th {\n",
+ " text-align: left;\n",
+ " }\n",
+ "\n",
+ " .dataframe tbody tr th {\n",
+ " vertical-align: top;\n",
+ " }\n",
+ "</style>\n",
+ "<table border=\"1\" class=\"dataframe\">\n",
+ " <thead>\n",
+ " <tr style=\"text-align: right;\">\n",
+ " <th></th>\n",
+ " <th>in</th>\n",
+ " <th>value</th>\n",
+ " <th>exp</th>\n",
+ " <th>unit</th>\n",
+ " <th>rest</th>\n",
+ " <th>len(rest)</th>\n",
+ " </tr>\n",
+ " </thead>\n",
+ " <tbody>\n",
+ " <tr>\n",
+ " <th>0</th>\n",
+ " <td>10</td>\n",
+ " <td>10</td>\n",
+ " <td></td>\n",
+ " <td></td>\n",
+ " <td></td>\n",
+ " <td>0</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>1</th>\n",
+ " <td>10k</td>\n",
+ " <td>10</td>\n",
+ " <td>k</td>\n",
+ " <td></td>\n",
+ " <td></td>\n",
+ " <td>0</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>2</th>\n",
+ " <td>10kOhm</td>\n",
+ " <td>10</td>\n",
+ " <td>k</td>\n",
+ " <td>Ohm</td>\n",
+ " <td></td>\n",
+ " <td>0</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>3</th>\n",
+ " <td>10k G</td>\n",
+ " <td>10</td>\n",
+ " <td>k</td>\n",
+ " <td></td>\n",
+ " <td>G</td>\n",
+ " <td>1</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>4</th>\n",
+ " <td>10M Hwat</td>\n",
+ " <td>10</td>\n",
+ " <td>M</td>\n",
+ " <td>H</td>\n",
+ " <td>wat</td>\n",
+ " <td>3</td>\n",
+ " </tr>\n",
+ " </tbody>\n",
+ "</table>\n",
+ "</div>"
+ ],
+ "text/plain": [
+ " in value exp unit rest len(rest)\n",
+ "0 10 10 0\n",
+ "1 10k 10 k 0\n",
+ "2 10kOhm 10 k Ohm 0\n",
+ "3 10k G 10 k G 1\n",
+ "4 10M Hwat 10 M H wat 3"
+ ]
+ },
+ "execution_count": 325,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "import re\n",
+ "r=re.compile(\"([0-9]+)( *)([EMpPnuTµkmGf]?) *(F|Ohm|Ω|H?) *(.*)\")\n",
+ "\n",
+ "tests = [\"10\", \"10k\", \"10kOhm\", \"10k G\", \"10M Hwat\"]\n",
+ "data=[]\n",
+ "\n",
+ "for t in tests:\n",
+ " m=r.match(t)\n",
+ " gs=m.groups()\n",
+ " data.append((t, gs[0], gs[2], gs[3], gs[4], len(gs[4])))\n",
+ "\n",
+ "pandas.DataFrame(data=data, columns=['in', 'value', 'exp', 'unit', 'rest', 'len(rest)'])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 300,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([[ 1.27270446, 0.04395931, 1.54053766, -0.29093601, 1.30028845],\n",
+ " [-0.12251453, -1.16148211, 0.53045512, 0.44172195, 0.94238916],\n",
+ " [-0.12981926, -0.98367131, 0.37159006, 0.6195868 , -0.90403497],\n",
+ " [ 0.26614445, 0.47932884, 0.23314929, -0.15904921, 1.3544832 ],\n",
+ " [-1.19267536, 2.33740053, -1.18444525, 0.44111548, 0.60629138],\n",
+ " [-1.45884344, 0.61256059, -0.97138815, -0.82263728, 0.68976108],\n",
+ " [ 1.08294243, 0.88823694, -0.19957563, 0.52466939, -0.38971842],\n",
+ " [-0.94265388, 1.86801751, 0.21990138, -1.34364849, 0.32846411],\n",
+ " [ 0.83686376, -1.03843546, 0.84131267, -1.10071726, -0.25169346],\n",
+ " [-0.50006954, 1.21361699, 0.14561531, -0.39272299, 0.30361834]])"
+ ]
+ },
+ "execution_count": 300,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "np.random.randn(10, 5)"
+ ]
+ }
+ ],
+ "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.5.4rc1"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}