Last active
December 7, 2015 23:11
-
-
Save jtyberg/63fe41605566fc1fe866 to your computer and use it in GitHub Desktop.
ipkernel json_clean no like numpy types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd\n", | |
"import numpy as np\n", | |
"from datetime import datetime, date\n", | |
"from ipykernel.jsonutil import json_clean" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"s = pd.Series({'int': 1,\n", | |
" 'float': 1.0,\n", | |
" 'date': datetime.now().date(), \n", | |
" 'timedelta': pd.Timedelta(hours=1)})" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"ename": "ValueError", | |
"evalue": "Can't clean for JSON: datetime.date(2015, 12, 7)", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", | |
"\u001b[1;32m<ipython-input-16-2369fb819ee6>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mjson_clean\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdate\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[1;32m/opt/conda/lib/python3.4/site-packages/ipykernel/jsonutil.py\u001b[0m in \u001b[0;36mjson_clean\u001b[1;34m(obj)\u001b[0m\n\u001b[0;32m 167\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 168\u001b[0m \u001b[1;31m# we don't understand it, it's probably an unserializable object\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 169\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Can't clean for JSON: %r\"\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[1;31mValueError\u001b[0m: Can't clean for JSON: datetime.date(2015, 12, 7)" | |
] | |
} | |
], | |
"source": [ | |
"json_clean(s.date)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"ename": "ValueError", | |
"evalue": "Can't clean for JSON: Timedelta('0 days 01:00:00')", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", | |
"\u001b[1;32m<ipython-input-17-89cdf84dbf04>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mjson_clean\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ms\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtimedelta\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[1;32m/opt/conda/lib/python3.4/site-packages/ipykernel/jsonutil.py\u001b[0m in \u001b[0;36mjson_clean\u001b[1;34m(obj)\u001b[0m\n\u001b[0;32m 167\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 168\u001b[0m \u001b[1;31m# we don't understand it, it's probably an unserializable object\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 169\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Can't clean for JSON: %r\"\u001b[0m \u001b[1;33m%\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[1;31mValueError\u001b[0m: Can't clean for JSON: Timedelta('0 days 01:00:00')" | |
] | |
} | |
], | |
"source": [ | |
"json_clean(s.timedelta)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"backports-abc==0.4\r\n", | |
"certifi==14.5.14\r\n", | |
"conda==3.18.8\r\n", | |
"conda-env==2.4.4\r\n", | |
"decorator==4.0.4\r\n", | |
"ipykernel==4.1.1\r\n", | |
"ipython==4.0.0\r\n", | |
"ipython-genutils==0.1.0\r\n", | |
"ipywidgets==4.1.0\r\n", | |
"Jinja2==2.8\r\n", | |
"jsonschema==2.4.0\r\n", | |
"jupyter==1.0.0\r\n", | |
"jupyter-client==4.1.1\r\n", | |
"jupyter-cms==0.2.1\r\n", | |
"jupyter-console==4.0.3\r\n", | |
"jupyter-core==4.0.6\r\n", | |
"jupyter-dashboards==0.2.0\r\n", | |
"jupyter-declarativewidgets==0.2.0\r\n", | |
"MarkupSafe==0.23\r\n", | |
"matplotlib==1.4.3\r\n", | |
"mistune==0.7.1\r\n", | |
"nbconvert==4.0.0\r\n", | |
"nbformat==4.0.1\r\n", | |
"nose==1.3.7\r\n", | |
"notebook==4.0.6\r\n", | |
"numpy==1.10.1\r\n", | |
"pandas==0.17.1\r\n", | |
"path.py==0.0.0\r\n", | |
"pexpect==3.3\r\n", | |
"pickleshare==0.5\r\n", | |
"ptyprocess==0.5\r\n", | |
"pycosat==0.6.1\r\n", | |
"Pygments==2.0.2\r\n", | |
"pyparsing==2.0.3\r\n", | |
"python-dateutil==2.4.2\r\n", | |
"pytz==2015.7\r\n", | |
"PyYAML==3.11\r\n", | |
"pyzmq==14.7.0\r\n", | |
"qtconsole==4.1.1\r\n", | |
"requests==2.8.1\r\n", | |
"scandir==1.1\r\n", | |
"scikit-learn==0.16.1\r\n", | |
"scipy==0.16.0\r\n", | |
"seaborn==0.6.0\r\n", | |
"simplegeneric==0.8.1\r\n", | |
"six==1.10.0\r\n", | |
"terminado==0.5\r\n", | |
"tornado==4.3\r\n", | |
"traitlets==4.0.0\r\n", | |
"wheel==0.26.0\r\n", | |
"Whoosh==2.7.0\r\n" | |
] | |
} | |
], | |
"source": [ | |
"!pip freeze" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"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.4.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment