Skip to content

Commit d7f4b63

Browse files
authored
Merge pull request #1016 from jfbercher/master
[varInspector] Fix #1014 and #1015 - reload on %reset magic and fix print on python2
2 parents 0a24d76 + 7ea5229 commit d7f4b63

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

src/jupyter_contrib_nbextensions/nbextensions/varInspector/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ The initial configuration can be given using the IPython-contrib nbextensions fa
2525

2626
## Notes
2727
- The displayed size of variables use the `getsizeof()` python method. This method doesn't work for all types, so the reported size is to be considered with some caution. The extension includes some code to correctly return the size of numpy arrays, pandas Series and DataFrame but the size for some other types may be incorrect.
28-
- The extension builds on some
29-
[example code](https://github.com/jupyter-widgets/ipywidgets/blob/ffa094e061c899292036049b00ff93e46e8b4691/docs/source/examples/Variable%20Inspector.ipynb)
30-
provided by the ipywidgets package (essentially the `_fill` method).
28+
- The extension builds on some code provided [here](https://github.com/ipython/ipywidgets/blob/master/docs/source/examples/Variable%20Inspector.ipynb) (essentially the `_fill` method)
3129
- The extension uses Christian Bach's [table sorter jquery plugin](https://github.com/christianbach/tablesorter). License file is included.
3230

3331

3432
## History
3533

3634
- @jfbercher march 22, 2017 -- initial release
37-
- @jfbercher april 03, 2017 -- multiple kernel support. added support for R kernels.
35+
- @jfbercher april 03, 2017 -- multiple kernel support. added support for R kernels.
36+
- @jfbercher june 30, 2017 -- fixed #1014 (use of `%reset` with IPython kernel) and #1015 printing with python 2 kernel.

src/jupyter_contrib_nbextensions/nbextensions/varInspector/main.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,13 @@ function html_table(jsonVars) {
144144

145145
function code_exec_callback(msg) {
146146
var jsonVars = msg.content['text'];
147-
$('#varInspector').html(html_table(jsonVars))
147+
var notWellDefined = false;
148+
if (msg.content.evalue)
149+
notWellDefined = msg.content.evalue == "name 'var_dic_list' is not defined" ||
150+
msg.content.evalue.substr(0,28) == "Error in cat(var_dic_list())"
151+
//means that var_dic_list was cleared ==> need to retart the extension
152+
if (notWellDefined) varInspector_init()
153+
else $('#varInspector').html(html_table(jsonVars))
148154

149155
require(['nbextensions/varInspector/jquery.tablesorter.min'],
150156
function() {

src/jupyter_contrib_nbextensions/nbextensions/varInspector/varInspector.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Description: The Variable Inspector extension collects all defined variables and
44
Link: README.md
55
Icon: icon.png
66
Main: main.js
7-
Compatibility: 4.x
7+
Compatibility: 4.x, 5.x
88
Parameters:
99
- name: varInspector.window_display
1010
description: Display window at startup

src/jupyter_contrib_nbextensions/nbextensions/varInspector/var_list.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
from __future__ import print_function
2-
3-
import json
41
from sys import getsizeof
5-
6-
from IPython import get_ipython
72
from IPython.core.magics.namespace import NamespaceMagics
8-
3+
from IPython import get_ipython
4+
import json
95
_nms = NamespaceMagics()
106
_Jupyter = get_ipython()
117
_nms.shell = _Jupyter.kernel.shell
@@ -24,9 +20,9 @@ def _getsizeof(x):
2420

2521
def var_dic_list():
2622
types_to_exclude = ['module', 'function', 'builtin_function_or_method',
27-
'instance', '_Feature']
23+
'instance', '_Feature', 'type', 'ufunc']
2824
values = _nms.who_ls()
29-
vardic = [{'varName': v, 'varType': type(eval(v)).__name__, 'varSize': _getsizeof(eval(v)), 'varContent': str(eval(v))[:200]} # noqa
25+
vardic = [{'varName': v, 'varType': type(eval(v)).__name__, 'varSize': str(_getsizeof(eval(v))), 'varContent': str(eval(v))[:200]} # noqa
3026
for v in values if (v not in ['_html', '_nms', 'NamespaceMagics', '_Jupyter']) & (type(eval(v)).__name__ not in types_to_exclude)] # noqa
3127
return json.dumps(vardic)
3228

0 commit comments

Comments
 (0)